void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); return; } var shapesData0Arr = new Vector4[_shapes.Count]; var shapesData1Arr = new Vector4[_shapes.Count]; for (int i = 0; i < _shapes.Count; i++) { var shape = _shapes[i]; var shapePos = shape.transform.position; shapesData0Arr[i] = new Vector4((float)shape.Type, (float)shape.Operator); if (shape.Type == RayMarchingShapeType.Sphere) { shapesData1Arr[i] = new Vector4(shapePos.x, shapePos.y, shapePos.z, shape.transform.localScale.x); } else if (shape.Type == RayMarchingShapeType.Box) { shapesData1Arr[i] = new Vector4(shapePos.x, shapePos.y, shapePos.z, shape.transform.localScale.x); } } EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); if (_shapes.Count > 0) { EffectMaterial.SetInt("_ShapesCount", _shapes.Count); EffectMaterial.SetVectorArray("_ShapesData0Arr", shapesData0Arr); EffectMaterial.SetVectorArray("_ShapesData1Arr", shapesData1Arr); } CustomGraphicsBlit(source, destination, EffectMaterial, 0); }