示例#1
0
 private void ChangeFunction()
 {
     if (transitionMode == TransitionMode.Cycle)
     {
         nextFunction = (GPUFunction)(((int)function + 1) % 5);
     }
     else
     {
         nextFunction = (GPUFunction)UnityEngine.Random.Range(0, 5);
     }
 }
示例#2
0
        private void UpdatetFunctionOnGPU()
        {
            float step = 2f / resolution;

            computeShader.SetInt(resolutionId, resolution);
            computeShader.SetFloat(stepId, step);
            computeShader.SetFloat(timeId, Time.time);

            if (isTransitioning)
            {
                float progress = duration / transitionDuration;
                if (progress >= transitionDuration)
                {
                    duration        = 0f;
                    function        = nextFunction;
                    isTransitioning = false;
                }
                else
                {
                    computeShader.SetFloat(transitionProgressId, Mathf.SmoothStep(0f, 1f, progress));
                }
            }

            //int kernelIndex = (int)function + (int)(isTransitioning ? nextFunction : function) * 5;
            int kernelIndex = (int)function * 6 + nextFunction - function;

            computeShader.SetBuffer(kernelIndex, positionId, positionBuffer);

            int groups = Mathf.CeilToInt(resolution / 8f);

            computeShader.Dispatch(kernelIndex, groups, groups, 1);

            material.SetBuffer(positionId, positionBuffer);
            material.SetFloat(stepId, step);
            Bounds bounds = new Bounds(Vector3.zero, new Vector3(2f, 2f + 2f / resolution, 2f));

            Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, resolution * resolution);
        }