Beispiel #1
0
            public DepthTextureMode Render(Camera camera, OceanCameraTask oceanCamera, ICameraTaskData data)
            {
                var quality = oceanCamera.projectSetting.Reflection;

                if ((data.PreparedContents & PreparedContent.ReflectionTexture) != 0)
                {
                    InternalRender(camera, oceanCamera, quality, data);
                }
                return(DepthTextureMode.None);
            }
Beispiel #2
0
            internal void InternalRender(Camera camera, OceanCameraTask oceanCamera, ReflectionProjectSetting setting, ICameraTaskData data)
            {
                if (camera.orthographic)
                {
                    return;
                }

                var textureSize             = RenderHelper.GetTextureSize(camera, setting.TextureScale);
                var reflectionRenderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y);

                renderCamera.renderingPath = setting.RenderingPath;
                RenderHelper.CopyCameraOptions(camera, renderCamera);
                RenderHelper.SetLayerWithoutWater(renderCamera, setting.CullingMask);
                RenderHelper.CopySkyBox(oceanCamera, skybox);

                {
                    Vector3 pos    = new Vector3(0, data.Height, 0);
                    Vector3 normal = data.Normal;

                    // Reflect camera around reflection plane
                    float   d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
                    Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

                    Matrix4x4 reflection = Matrix4x4.zero;
                    CalculateReflectionMatrix(ref reflection, reflectionPlane);
                    renderCamera.transform.position  = reflection.MultiplyPoint(camera.transform.position);
                    renderCamera.worldToCameraMatrix = camera.worldToCameraMatrix * reflection;

                    // Setup oblique projection matrix so that near plane is our reflection
                    // plane. This way we clip everything below/above it for free.
                    Vector4 clipPlane = CameraSpacePlane(renderCamera, pos, normal, 1.0f);
                    renderCamera.projectionMatrix = camera.CalculateObliqueMatrix(clipPlane);

                    //// Set custom culling matrix from the current camera
                    renderCamera.cullingMatrix = camera.projectionMatrix * camera.worldToCameraMatrix;

                    Vector3 euler = camera.transform.eulerAngles;
                    renderCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
                }

                using (new RenderHelper.InvertCullingScope())
                {
                    using (new RenderHelper.PointLightsScope(setting.EnablePointLights))
                    {
                        oceanCamera.TaskController.OnPreReflectionRender(oceanCamera);
                        renderCamera.targetTexture = reflectionRenderTexture;
                        renderCamera.Render();
                        renderCamera.targetTexture = null;
                        oceanCamera.TaskController.OnPostReflectionRender(oceanCamera);
                    }
                }

                ReflectionTexture = reflectionRenderTexture;
                SetValuesToShader();
            }