private void UpdateFunctionOnGPU() { float step = 2f / resolution; computeShader.SetInt(resolutionID, resolution); computeShader.SetFloat(stepID, step); computeShader.SetFloat(timeID, Time.time); if (transitioning) { computeShader.SetFloat( transitionProgressiD, Mathf.SmoothStep(0f, 1f, duration / transitionDuration)); } int kernelIndex = function.indexNumber + (int)(transitioning ? previousFunction.indexNumber : currentFunction.indexNumber) * function.GetFunctionCount(); computeShader.SetBuffer(kernelIndex, positionsID, positionsBuffer); int groups = Mathf.CeilToInt(resolution / 8f); computeShader.Dispatch(kernelIndex, groups, groups, 1); material.SetBuffer(positionsID, positionsBuffer); material.SetFloat(stepID, step); var bounds = new Bounds(Vector3.zero, Vector3.one * (2f + 2f / resolution)); Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, resolution * resolution); }