protected virtual void Start() { int bufSize; system = Build(vertexCount, out bufSize); system.transform.parent = transform; system.transform.localPosition = Vector3.zero; system.transform.localScale = Vector3.one; system.transform.localRotation = Quaternion.identity; mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } particleUpdateMat.SetFloat("_SimulationTexSize", bufSize); particleUpdateMat.SetFloat("_SimulationTexDeltaSize", 1f / bufSize); particleUpdateMat.SetFloat("_SimulationParticleCount", bufSize * bufSize); SetProps(); ReadMRT.Render(particleUpdateMat, 0); // init // set display mat particleDisplayMat.SetTexture(_PositionBufferKey, ReadMRT.RenderTextures[0]); particleDisplayMat.SetTexture(_VelocityBufferKey, ReadMRT.RenderTextures[1]); particleDisplayMat.SetTexture(_RotationBufferKey, ReadMRT.RenderTextures[2]); }
void Start() { int bufSize; Vector3[] meshVertices; system = Build(vertexCount, out bufSize, out meshVertices); system.transform.parent = transform; mrts = new MRT[3]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } // create a render texture and transfer the initial particle postions to the update shader initialPos = new RenderTexture(bufSize, bufSize, 24); initialPos.format = RenderTextureFormat.ARGBFloat; RenderTexture.active = initialPos; Texture2D tempTexture = new Texture2D(initialPos.width, initialPos.height, TextureFormat.RGBAFloat, false); tempTexture.ReadPixels(new Rect(0, 0, initialPos.width, initialPos.height), 0, 0, false); for (int c = 0, i = 0; c < initialPos.width; c++) { for (int r = 0; r < initialPos.height; r++, i++) { tempTexture.SetPixel(r, c, new Color(meshVertices[i].x, meshVertices[i].y, meshVertices[i].z, 1)); //Debug.Log(meshVertices[i].x.ToString()+" "+meshVertices[i].y.ToString()+" "+meshVertices[i].z.ToString() ); } } tempTexture.Apply(); RenderTexture.active = null; Graphics.Blit(tempTexture, initialPos); SPH_UpdateMat.SetTexture("_PosTex", initialPos); SPH_UpdateDensityMat.SetTexture("_PosTex", initialPos); mrts[2].Render(SPH_UpdateDensityMat); var pressureBuffers = mrts[2].RenderTextures; SPH_UpdateMat.SetTexture("_DensityTex", pressureBuffers[0]); SPH_UpdateMat.SetTexture("_PressureTex", pressureBuffers[1]); ReadMRT.Render(SPH_UpdateMat); var buffers = ReadMRT.RenderTextures; RenderTexture.active = pressureBuffers[0]; tempTexture = new Texture2D(buffers[1].width, buffers[1].height, TextureFormat.RGBAFloat, false); tempTexture.ReadPixels(new Rect(0, 0, buffers[1].width, buffers[1].height), 0, 0, false); for (int i = 0; i < tempTexture.width; i++) { for (int j = 0; j < tempTexture.height; j++) { //Debug.Log(tempTexture.GetPixel(j, i).r.ToString() + " " + tempTexture.GetPixel(j, i).g.ToString() + " " + tempTexture.GetPixel(j, i).b.ToString()); } } RenderTexture.active = null; }
// Use this for initialization void Start() { plane = GetComponent <MeshFilter>().mesh; int bufSize = Mathf.CeilToInt(Mathf.Sqrt(plane.vertexCount * 1.0f)); mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } ReadMRT.Render(particleUpdateMat, 0); // init }
void Start() { int bufSize; system = Build(vertexCount, out bufSize); system.transform.parent = transform; mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } ReadMRT.Render(particleUpdateMat, 0); // init }
void Start() { cam = Camera.main; material = GetComponent <Renderer>().material; timeOffset = Random.Range(0f, 100f); var mesh = OctahedronSphereCreator.Create(subdivisions, radius); mesh = Utils.MeshDisperser.Disperse(mesh); // set vertices center var tangents = new Vector4[mesh.vertexCount]; for (int i = 0, n = tangents.Length; i < n; i += 3) { var v0 = mesh.vertices[i]; var v1 = mesh.vertices[i + 1]; var v2 = mesh.vertices[i + 2]; tangents[i] = tangents[i + 1] = tangents[i + 2] = (v0 + v1 + v2) / 3f; } mesh.tangents = tangents; int count = mesh.triangles.Length / 3; mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(count, 1); } ReadMRT.Render(updateMaterial, 0); // init material.SetTexture(_PositionBufferKey, ReadMRT.RenderTextures[0]); material.SetTexture(_VelocityBufferKey, ReadMRT.RenderTextures[1]); material.SetTexture(_RotationBufferKey, ReadMRT.RenderTextures[2]); GetComponent <MeshFilter>().mesh = mesh; }