예제 #1
0
        void Setup(GPUComputeParticleSystem system)
        {
            var buffer = system.ParticleBuffer;

            GPUParticle[] particles = new GPUParticle[buffer.count];
            buffer.GetData(particles);

            var count = particles.Length;

            bounds = new List <CPBound>();
            Bintree(Vector3.zero, Vector3.one, depth);
            boundsBuffer = new ComputeBuffer(bounds.Count, Marshal.SizeOf(typeof(CPBound_t)));
            boundsBuffer.SetData(bounds.Select(b => b.Structure()).ToArray());

            boundsReferencesBuffer = new ComputeBuffer(count, Marshal.SizeOf(typeof(int)));

            var kernel = shader.FindKernel("Octree");

            shader.SetBuffer(kernel, "_Bounds", boundsBuffer);
            shader.SetInt("_BoundsCount", bounds.Count);
            shader.SetBuffer(kernel, "_BoundsReferences", boundsReferencesBuffer);
            Dispatch(kernel, system);

            shader.SetBuffer(0, "_BoundsReferences", boundsReferencesBuffer);
        }
예제 #2
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            shader.SetFloat("_Time", ticker);
            shader.SetFloat("_Scale", scale);
            shader.SetFloat("_Intensity", intensity);

            base.Dispatch(system);
        }
예제 #3
0
 public void Dispatch(GPUComputeParticleSystem system)
 {
     updaters.ForEach(updater => {
         if (updater.gameObject.activeSelf)
         {
             updater.Dispatch(system);
         }
     });
 }
예제 #4
0
 public void Init(GPUComputeParticleSystem system)
 {
     updaters.ForEach(updater => {
         if (updater.gameObject.activeSelf)
         {
             updater.Init(system.ParticleBuffer);
         }
     });
 }
예제 #5
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            shader.SetVector("_Force", force);
            shader.SetVector("_Seed", seed);
            shader.SetFloat("_DT", Time.deltaTime * lifetimeSpeed);
            shader.SetVector("_EmissionCenter", emissionArea.center);
            shader.SetVector("_EmissionSize", emissionArea.size);

            base.Dispatch(system);
        }
예제 #6
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            if (stateBuffer == null)
            {
                Init(system.ParticleBuffer);
            }

            shader.SetFloat("_DT", Time.deltaTime * speed);
            shader.SetFloat("_Scale", scale);
            base.Dispatch(system);
        }
예제 #7
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            shader.SetFloat("_T", t);
            shader.SetFloat("_Time", ticker);
            shader.SetFloat("_DT", Time.deltaTime * 3f);
            shader.SetFloat("_Scale", scale);
            shader.SetFloat("_Intensity", intensity);
            shader.SetFloat("_Power", power);
            shader.SetVector("_Seed", seed);

            base.Dispatch((int)mode, system);
        }
예제 #8
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            shader.SetFloat("_Size", size);
            shader.SetFloat("_Intensity", intensity);
            shader.SetFloat("_Speed", speed);

            shader.SetFloat("_R", 1f / system.ParticleBuffer.count);
            shader.SetFloat("_Time", ticker);
            shader.SetFloat("_DT", Time.deltaTime * speed);

            base.Dispatch((int)mode, system);
        }
예제 #9
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            // shader.SetVector("_GravityDirection", system.transform.TransformDirection(direction));
            // Debug.Log(system.transform.TransformDirection(direction));
            // shader.SetFloat("_Gravity", gravity);
            // shader.SetVector("_GravityDirection", direction);

            // shader.SetVector("_GravityDirection", system.transform.TransformDirection(direction));
            shader.SetVector("_GravityDirection", system.transform.InverseTransformDirection(direction));
            shader.SetFloat("_Gravity", gravity);
            base.Dispatch(system);
        }
예제 #10
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            if (boundsBuffer == null)
            {
                Setup(system);
            }

            UpdateBounds();

            shader.SetFloat("_T", t);
            shader.SetBuffer(dispatchID, "_Bounds", boundsBuffer);
            base.Dispatch(system);
        }
예제 #11
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            if (boundsBuffer == null)
            {
                Setup(system);
            }

            UpdateBounds();

            shader.SetBuffer(dispatchID, "_Bounds", boundsBuffer);
            shader.SetFloat("_T", (mode == ExtrusionMode.Physics || mode == ExtrusionMode.Explosion) ? 1f : t);
            base.Dispatch(system);
        }
예제 #12
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            if (fromBuffer == null)
            {
                Init(system.ParticleBuffer);
            }

            if (fromBuffer != null)
            {
                shader.SetFloat("_RT", rt);
                base.Dispatch(system);
            }
        }
예제 #13
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GPUComputeParticleSystem system = target as GPUComputeParticleSystem;

            // system.updaters;

            EditorGUILayout.LabelField("updaters");
            // EditorGUILayout.BeginHorizontal();

            EditorGUI.indentLevel++;

            int n = system.updaters.Count;

            for (int i = 0; i < n; i++)
            {
                var updater = system.updaters[i];
                if (updater == null)
                {
                    system.updaters.RemoveAt(i);
                    return;
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label(updater.name);
                if (i != 0 && GUILayout.Button("up", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    var tmp = system.updaters[i];
                    system.updaters[i]     = system.updaters[i - 1];
                    system.updaters[i - 1] = tmp;
                    break;
                }
                else if (i != n - 1 && GUILayout.Button("down", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    var tmp = system.updaters[i];
                    system.updaters[i]     = system.updaters[i + 1];
                    system.updaters[i + 1] = tmp;
                    break;
                }
                else if (GUILayout.Button("Remove", GUILayout.Width(50), GUILayout.Height(20)))
                {
                    system.updaters.RemoveAt(i);
                    break;
                }
                GUILayout.EndHorizontal();
            }

            // EditorGUILayout.EndHorizontal();
        }
예제 #14
0
        public override void Dispatch(GPUComputeParticleSystem system)
        {
            CheckInit();

            int count = explosions.Count;

            if (count > 0)
            {
                explosionBuffer.SetData(explosions.ToArray());
                shader.SetBuffer(0, "_Explosions", explosionBuffer);
                shader.SetInt("_ExplosionsCount", count);
                base.Dispatch(system);

                explosions.Clear();
            }
        }
예제 #15
0
 protected void Dispatch(int id, GPUComputeParticleSystem system)
 {
     shader.SetBuffer(id, _BufferKey, system.ParticleBuffer);
     shader.Dispatch(id, system.ParticleBuffer.count / _Thread + 1, 1, 1);
 }
예제 #16
0
 public virtual void Dispatch(GPUComputeParticleSystem system)
 {
     Dispatch(dispatchID, system);
 }