private void ComputeVisibleAreas(Bounds waterfallBounds)
        {
            _clipeePoints.Clear();
            _clipeePoints.Add(_renderingCameraFrustum.TopLeft);
            _clipeePoints.Add(_renderingCameraFrustum.TopRight);
            _clipeePoints.Add(_renderingCameraFrustum.BottomRight);
            _clipeePoints.Add(_renderingCameraFrustum.BottomLeft);

            bool isRenderingCameraFullyContainedInWaterBox = true;

            //Finding visible Waterfall Area

            Vector2 waterfallBoundsMin = waterfallBounds.min;
            Vector2 waterfallBoundsMax = waterfallBounds.max;

            //Clip camera frustrum against waterfall box edges to find the visible water area
            //top edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: false, edgePosition: waterfallBoundsMax.y);
            //right edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: false, isBottomOrLeftEdge: false, edgePosition: waterfallBoundsMax.x);
            //bottom edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: true, edgePosition: waterfallBoundsMin.y);
            //left edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: false, isBottomOrLeftEdge: true, edgePosition: waterfallBoundsMin.x);

            _visibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, true, _farClipPlane);
        }
Example #2
0
        private void ComputeVisibleAreas(Bounds waterBounds)
        {
            var materialModule = _materialModule as WaterMaterialModule;

            bool isReflectionEnabled = materialModule.IsReflectionEnabled;

            _clipeePoints.Clear();
            _clipeePoints.Add(_renderingCameraFrustum.TopLeft);
            _clipeePoints.Add(_renderingCameraFrustum.TopRight);
            _clipeePoints.Add(_renderingCameraFrustum.BottomRight);
            _clipeePoints.Add(_renderingCameraFrustum.BottomLeft);

            bool isRenderingCameraFullyContainedInWaterBox = true;

            //Finding visible Water Area

            Vector2 waterBoundsMin = waterBounds.min;
            Vector2 waterBoundsMax = waterBounds.max;

            //Clip camera frustrum against water box edges to find the visible water area
            //top edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: false, edgePosition: waterBoundsMax.y);
            //right edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: false, isBottomOrLeftEdge: false, edgePosition: waterBoundsMax.x);
            //bottom edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: true, edgePosition: waterBoundsMin.y);
            //left edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: false, isBottomOrLeftEdge: true, edgePosition: waterBoundsMin.x);

            bool isFakePerspectiveEnabled = materialModule.IsFakePerspectiveEnabled;

            bool computePixelSize = !Refraction.RenderTextureUseFixedSize || !(isFakePerspectiveEnabled ? RefractionPartiallySubmergedObjects.RenderTextureUseFixedSize : Reflection.RenderTextureUseFixedSize);

            _wholeWaterVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, computePixelSize, _farClipPlane, true, isReflectionEnabled && !isFakePerspectiveEnabled, reflectionYOffset: ReflectionYOffset, reflectionZOffset: ReflectionZOffset, reflectionAxis: -waterBoundsMin.y, reflectionFrustumHeightScalingFactor: Reflection.ViewingFrustumHeightScalingFactor);

            if (isFakePerspectiveEnabled)
            {
                float waterBoxHeight = waterBoundsMax.y - waterBoundsMin.y;

                bool computeRefractionProperties = !materialModule.IsRefractionEnabled;

                float surfaceLevel  = waterBoundsMin.y + waterBoxHeight * materialModule.GetSurfaceLevelNormalized();
                float submergeLevel = waterBoundsMin.y + waterBoxHeight * materialModule.GetSubmergeLevelNormalized();

                //Finding visible Surface Area
                isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: true, edgePosition: surfaceLevel);
                _surfaceVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, !Reflection.RenderTextureUseFixedSize, _farClipPlane, computeRefractionProperties, isReflectionEnabled, reflectionYOffset: ReflectionYOffset, reflectionZOffset: ReflectionZOffset, reflectionAxis: waterBoundsMax.y, reflectionFrustumHeightScalingFactor: Reflection.ViewingFrustumHeightScalingFactor);

                //Finding visible Surface Area below submerge level
                isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstAABBEdge(_clipeePoints, isBottomOrTopEdge: true, isBottomOrLeftEdge: false, edgePosition: submergeLevel);
                _surfaceBelowSubmergeLevelVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, !ReflectionPartiallySubmergedObjects.RenderTextureUseFixedSize, _farClipPlane, false, isReflectionEnabled, reflectionYOffset: ReflectionYOffset, reflectionZOffset: ReflectionZOffset, reflectionAxis: submergeLevel, reflectionFrustumHeightScalingFactor: ReflectionPartiallySubmergedObjects.ViewingFrustumHeightScalingFactor);
            }
        }
        private void ComputeVisibleAreas(Camera currentRenderingCamera, Bounds waterBounds)
        {
            bool isReflectionEnabled = _materialModule.IsReflectionEnabled;

            _clipeePoints.Clear();
            _clipeePoints.Add(_renderingCameraFrustum.WaterLocalSpace.TopLeft);
            _clipeePoints.Add(_renderingCameraFrustum.WaterLocalSpace.TopRight);
            _clipeePoints.Add(_renderingCameraFrustum.WaterLocalSpace.BottomRight);
            _clipeePoints.Add(_renderingCameraFrustum.WaterLocalSpace.BottomLeft);

            bool isRenderingCameraFullyContainedInWaterBox = true;

            //Fidning visible Water Area

            Vector2 waterBoundsMin = waterBounds.min;
            Vector2 waterBoundsMax = waterBounds.max;

            //Clip camera frustrum against water box edges to find the visible water area
            //top edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: true, keepInside: false, edgeValue: waterBoundsMax.y);
            //right edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: false, keepInside: false, edgeValue: waterBoundsMax.x);
            //bottom edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: true, keepInside: true, edgeValue: waterBoundsMin.y);
            //left edge
            isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: false, keepInside: true, edgeValue: waterBoundsMin.x);

            _fullWaterVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, _farClipPlane, isReflectionEnabled, reflectionAxis: -waterBoundsMin.y);

            if (_materialModule.IsFakePerspectiveEnabled)
            {
                float waterBoxHeight = waterBoundsMax.y - waterBoundsMin.y;

                //Finding visible Surface Area
                float surfaceLevel = waterBoundsMin.y + waterBoxHeight * _materialModule.SurfaceLevel;
                isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: true, keepInside: true, edgeValue: surfaceLevel);
                _surfaceVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, _farClipPlane, isReflectionEnabled, reflectionAxis: waterBoundsMax.y, viewingFrustrumHeightScalingFactor: _reflection.ViewingFrustumHeightScalingFactor);

                //Finding visible Surface Area below submerge level
                float submergeLevel = waterBoundsMin.y + waterBoxHeight * _materialModule.SurfaceSubmergeLevel;
                isRenderingCameraFullyContainedInWaterBox &= WaterUtility.ClipPointsAgainstEdge(_clipeePoints, isHorizontalEdge: true, keepInside: false, edgeValue: submergeLevel);
                _surfaceBelowSubmergeLevelVisibleArea.UpdateArea(_clipeePoints, _renderingCameraFrustum, isRenderingCameraFullyContainedInWaterBox, _farClipPlane, isReflectionEnabled, reflectionAxis: submergeLevel, viewingFrustrumHeightScalingFactor: _reflectionPartiallySubmergedObjects.ViewingFrustumHeightScalingFactor);
            }
        }