void Update() { CheckInit(); var dt = 1f / fps; var nSteps = _ticker.Count(); var dx = l / nGrids; var mass = density * dx * dx; sim.SetFloat(SHADER_DX, dx); sim.SetFloat(SHADER_DT, dt); sim.SetFloat(SHADER_T, tension / mass); if (Input.GetMouseButton(0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (collider.Raycast(ray, out hit, float.MaxValue)) { var pxPos = nGrids * hit.textureCoord; var projMat = Matrix4x4.Ortho(0f, nGrids, 0f, nGrids, -1f, 1f); var brushTex = brushMat.mainTexture; var brushSize = 0.128f * nGrids; var paintRect = new Rect(pxPos.x - 0.5f * brushSize, pxPos.y - 0.5f * brushSize, brushSize, brushSize); GL.PushMatrix(); GL.LoadIdentity(); GL.LoadProjectionMatrix(projMat); RenderTexture.active = _hvTex0; Graphics.DrawTexture(paintRect, brushTex, brushMat); RenderTexture.active = null; GL.PopMatrix(); } } for (var i = 0; i < nSteps; i++) { Graphics.Blit(_hvTex0, _hvTex1, sim, 0); Swap(); Graphics.Blit(_hvTex0, _nTex, sim, 1); } var mat = renderer.sharedMaterial; mat.SetTexture(SHADER_BUMP_TEX, _nTex); }