Beispiel #1
0
        private void CameraPreCull(Camera camera)
        {
            if (!gameObject.activeInHierarchy || WeatherMakerCommandBufferManagerScript.CameraStackCount > 1 || WeatherMakerScript.ShouldIgnoreCamera(this, camera, true))
            {
                return;
            }

            RenderReflection();
        }
Beispiel #2
0
        private void CameraPreCull(Camera camera)
        {
            if (!gameObject.activeInHierarchy || WeatherMakerCommandBufferManagerScript.CameraStack > 1 || WeatherMakerScript.ShouldIgnoreCamera(this, camera, true))
            {
                return;
            }

            if (!RequestRefresh(Time.renderedFrameCount))
            {
                return; //skip if not need to refresh on this frame
            }
            CreateWaterObjects(_camViewpoint);

            if (!_camReflections)
            {
                return;
            }

            // find out the reflection plane: position and normal in world space
            Vector3 planePos    = OceanRenderer.Instance.transform.position;
            Vector3 planeNormal = Vector3.up;

            // Optionally disable pixel lights for reflection/refraction
            int oldPixelLightCount = QualitySettings.pixelLightCount;

            if (_disablePixelLights)
            {
                QualitySettings.pixelLightCount = 0;
            }

            UpdateCameraModes(_camViewpoint, _camReflections);

            // Reflect camera around reflection plane
            float   d = -Vector3.Dot(planeNormal, planePos) - _clipPlaneOffset;
            Vector4 reflectionPlane = new Vector4(planeNormal.x, planeNormal.y, planeNormal.z, d);

            Matrix4x4 reflection = Matrix4x4.zero;

            CalculateReflectionMatrix(ref reflection, reflectionPlane);
            Vector3 newpos = reflection.MultiplyPoint(_camViewpoint.transform.position);

            _camReflections.worldToCameraMatrix = _camViewpoint.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(_camReflections, planePos, planeNormal, 1.0f);

            _camReflections.projectionMatrix = _camViewpoint.CalculateObliqueMatrix(clipPlane);

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

            _camReflections.targetTexture = _reflectionTexture;

            // Invert culling because view is mirrored
            bool oldCulling = GL.invertCulling;

            GL.invertCulling = !oldCulling;

            _camReflections.transform.position = newpos;
            Vector3 euler = _camViewpoint.transform.eulerAngles;

            _camReflections.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
            _camReflections.cullingMatrix         = _camReflections.projectionMatrix * _camReflections.worldToCameraMatrix;

            ForceDistanceCulling(_farClipPlane);

            if (WeatherMakerCommandBufferManagerScript.Instance != null)
            {
                WeatherMakerCommandBufferManagerScript.Instance.RenderCamera(_camReflections);
            }

            GL.invertCulling = oldCulling;

            // Restore pixel light count
            if (_disablePixelLights)
            {
                QualitySettings.pixelLightCount = oldPixelLightCount;
            }

            Refreshed(Time.renderedFrameCount); //remember this frame as last refreshed
        }