Beispiel #1
0
        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]);
        }
Beispiel #2
0
        public virtual void Simulate(MRT read, MRT write)
        {
            var buffers = read.RenderTextures;

            material.SetTexture(_PositionBufferKey, buffers[0]);
            material.SetTexture(_VelocityBufferKey, buffers[1]);
            material.SetTexture(_RotationBufferKey, buffers[2]);
            write.Render(material);
        }
Beispiel #3
0
        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;
        }