internal void Setup(RenderingCameraInformation renderingCameraInformation)
        {
            CurrentCamera = renderingCameraInformation.CurrentCamera;

            Position = _mainModule.TransformPointWorldToLocal(renderingCameraInformation.Position);

            var cameraRotationEulerAngles = renderingCameraInformation.RotationEulerAngles;

            cameraRotationEulerAngles.z -= _mainModule.ZRotation;
            Rotation = cameraRotationEulerAngles;

            IsIsometric = renderingCameraInformation.IsIsometric;

            var nTopLeft     = _mainModule.TransformPointWorldToLocal(renderingCameraInformation.nearFrustumPlaneTopLeft);
            var nTopRight    = _mainModule.TransformPointWorldToLocal(renderingCameraInformation.nearFrustumPlaneTopRight);
            var nBottomLeft  = _mainModule.TransformPointWorldToLocal(renderingCameraInformation.nearFrustumPlaneBottomLeft);
            var nBottomRight = _mainModule.TransformPointWorldToLocal(renderingCameraInformation.nearFrustumPlaneBottomRight);

            if (CurrentCamera.orthographic)
            {
                if (!IsIsometric)
                {
                    TopLeft     = nTopLeft;
                    TopRight    = nTopRight;
                    BottomLeft  = nBottomLeft;
                    BottomRight = nBottomRight;
                }
                else
                {
                    var cameraForwardDirection = _mainModule.TransformVectorWorldToLocal(renderingCameraInformation.ForwardDirection);

                    TopLeft     = ComputeIntersectionOfLineWithWaterPlane(nTopLeft, cameraForwardDirection);
                    TopRight    = ComputeIntersectionOfLineWithWaterPlane(nTopRight, cameraForwardDirection);
                    BottomLeft  = ComputeIntersectionOfLineWithWaterPlane(nBottomLeft, cameraForwardDirection);
                    BottomRight = ComputeIntersectionOfLineWithWaterPlane(nBottomRight, cameraForwardDirection);
                }
            }
            else
            {
                var halfWidth  = _mainModule.Width * 0.5f;
                var halfHeight = _mainModule.Height * 0.5f;

                var cameraPosition      = Position;
                var cameraZPositionSign = cameraPosition.z > 0f;

                TopLeft     = cameraZPositionSign ^ (nTopLeft.z > cameraPosition.z) ? ComputeIntersectionOfLineWithWaterPlane(cameraPosition, nTopLeft - cameraPosition) : new Vector2(-halfWidth, halfHeight);
                TopRight    = cameraZPositionSign ^ (nTopRight.z > cameraPosition.z) ? ComputeIntersectionOfLineWithWaterPlane(cameraPosition, nTopRight - cameraPosition) : new Vector2(halfWidth, halfHeight);
                BottomLeft  = cameraZPositionSign ^ (nBottomLeft.z > cameraPosition.z) ? ComputeIntersectionOfLineWithWaterPlane(cameraPosition, nBottomLeft - cameraPosition) : new Vector2(-halfWidth, -halfHeight);
                BottomRight = cameraZPositionSign ^ (nBottomRight.z > cameraPosition.z) ? ComputeIntersectionOfLineWithWaterPlane(cameraPosition, nBottomRight - cameraPosition) : new Vector2(halfWidth, -halfHeight);
            }
        }
示例#2
0
        internal override void Render(RenderingCameraInformation renderingCameraInformation)
#endif
        {
            ComputeVisibleAreas(_meshModule.BoundsLocalSpace);

#if !GAME_2D_WATER_KIT_LWRP && !GAME_2D_WATER_KIT_URP
            int pixelLightCount = QualitySettings.pixelLightCount;
            if (!_renderPixelLights)
            {
                QualitySettings.pixelLightCount = 0;
            }
#endif

            _meshModule.SetRendererActive(false);

            Color backgroundColor = _renderingCameraFrustum.CurrentCamera.backgroundColor;
            backgroundColor.a = 1f;

            bool isUsingOpaqueRenderQueue = _materialModule.RenderQueue == 2000;

            if (!isUsingOpaqueRenderQueue)
            {
                var     refractionRenderingPorperties = _visibleArea.RefractionProperties;
                Vector3 maskPosition = refractionRenderingPorperties.Position;
                maskPosition.z += refractionRenderingPorperties.NearClipPlane + 0.001f;
                SetupRefractionMask(maskPosition);
                SetRefractionMaskLayer(Refraction.GetValidRefractionMaskLayer());
            }

#if GAME_2D_WATER_KIT_LWRP || GAME_2D_WATER_KIT_URP
            Refraction.Render(context, _g2dwCamera, _visibleArea, backgroundColor, _allowHDR, _allowMSAA);
#else
            Refraction.Render(_g2dwCamera, _visibleArea, backgroundColor, _allowHDR, _allowMSAA);
#endif

            var materialModule = _materialModule as WaterfallMaterialModule;
            materialModule.SetRefractionRenderTexture(Refraction.RenderTexture);

            _refractionMask.SetActive(false);

#if !GAME_2D_WATER_KIT_LWRP && !GAME_2D_WATER_KIT_URP
            QualitySettings.pixelLightCount = pixelLightCount;
#endif

            _meshModule.SetRendererActive(true);

            var worldToVisibleAreaMatrix = Matrix4x4.TRS(_visibleArea.RefractionProperties.Position, _visibleArea.RefractionProperties.Rotation, new Vector3(1f, 1f, -1f)).inverse;
            var projectionMatrix         = _visibleArea.RefractionProperties.ProjectionMatrix;
            materialModule.SetWaterfallMatrix(projectionMatrix * worldToVisibleAreaMatrix * _mainModule.LocalToWorldMatrix);
            materialModule.ValidateMaterialPropertyBlock();
        }
示例#3
0
        internal override bool Setup(RenderingCameraInformation renderingCameraInformation)
        {
            bool isValidWaterSize = _mainModule.Width > 0f && _mainModule.Height > 0f;

            if (!isValidWaterSize)
            {
                return(false);
            }

            var materialModule = _materialModule as WaterMaterialModule;

            bool renderRefraction = materialModule.IsRefractionEnabled;
            bool renderReflection = materialModule.IsReflectionEnabled;
            bool fakePerspective  = materialModule.IsFakePerspectiveEnabled;

            if (!(renderReflection || renderRefraction || fakePerspective))
            {
                return(false);
            }

            var mainModule = _mainModule as WaterMainModule;

            var  largeWaterAreaManager       = mainModule.LargeWaterAreaManager;
            bool isConnectedToLargeWaterArea = largeWaterAreaManager != null;

            if (isConnectedToLargeWaterArea && largeWaterAreaManager.HasAlreadyRenderedCurrentFrame(renderingCameraInformation.CurrentCamera))
            {
                GetCurrentFrameRenderInformationFromLargeWaterAreaManager(largeWaterAreaManager, renderRefraction, renderReflection, fakePerspective);
                return(false);
            }

            _renderingCameraFrustum.Setup(renderingCameraInformation);

            Vector2 aabbMin     = _renderingCameraFrustum.AABBMin;
            Vector2 aabbMax     = _renderingCameraFrustum.AABBMax;
            Vector2 aabbExtents = (aabbMax - aabbMin) * 0.5f;
            Vector2 aabbCenter  = (aabbMax + aabbMin) * 0.5f;

            if (Mathf.Abs(aabbCenter.x) > (_mainModule.Width * 0.5f + aabbExtents.x))
            {
                return(false);
            }

            if (Mathf.Abs(aabbCenter.y) > (_mainModule.Height * 0.5f + aabbExtents.y))
            {
                return(false);
            }

            return(true);
        }
        internal override bool Setup(RenderingCameraInformation renderingCameraInformation)
        {
            bool isValidWaterfallSize = _mainModule.Width > 0f && _mainModule.Height > 0f;

            if (!isValidWaterfallSize)
            {
                return(false);
            }

            var materialModule = _materialModule as WaterfallMaterialModule;

            bool renderRefraction = materialModule.IsRefractionEnabled;

            if (!renderRefraction)
            {
                return(false);
            }

            _renderingCameraFrustum.Setup(renderingCameraInformation);

            Vector2 aabbMin     = _renderingCameraFrustum.AABBMin;
            Vector2 aabbMax     = _renderingCameraFrustum.AABBMax;
            Vector2 aabbExtents = (aabbMax - aabbMin) * 0.5f;
            Vector2 aabbCenter  = (aabbMax + aabbMin) * 0.5f;

            if (Mathf.Abs(aabbCenter.x) > (_mainModule.Width * 0.5f + aabbExtents.x))
            {
                return(false);
            }

            if (Mathf.Abs(aabbCenter.y) > (_mainModule.Height * 0.5f + aabbExtents.y))
            {
                return(false);
            }

            return(true);
        }
        internal override void Render(RenderingCameraInformation renderingCameraInformation)
#endif
        {
            var materialModule = _materialModule as WaterMaterialModule;

            bool renderRefraction = materialModule.IsRefractionEnabled;
            bool renderReflection = materialModule.IsReflectionEnabled;

            var mainModule = _mainModule as WaterMainModule;

            var  largeWaterAreaManager       = mainModule.LargeWaterAreaManager;
            bool isConnectedToLargeWaterArea = largeWaterAreaManager != null;

            ComputeVisibleAreas(!isConnectedToLargeWaterArea ? _meshModule.Bounds : largeWaterAreaManager.GetWaterObjectsBoundsRelativeToSpecifiedWaterObject(mainModule));

#if !GAME_2D_WATER_KIT_LWRP && !GAME_2D_WATER_KIT_URP
            int pixelLightCount = QualitySettings.pixelLightCount;
            if (!_renderPixelLights)
            {
                QualitySettings.pixelLightCount = 0;
            }
#endif

            _meshModule.SetRendererActive(false);

            Color backgroundColor = renderingCameraInformation.CurrentCamera.backgroundColor;
            backgroundColor.a = 1f;

            bool isUsingOpaqueRenderQueue = _materialModule.RenderQueue == 2000;

            if (renderRefraction && !isUsingOpaqueRenderQueue)
            {
                SetupRefractionMask();
            }

#if GAME_2D_WATER_KIT_LWRP || GAME_2D_WATER_KIT_URP
            _renderingContext = context;
#endif

            if (!materialModule.IsFakePerspectiveEnabled)
            {
                if (renderRefraction)
                {
                    if (!isUsingOpaqueRenderQueue)
                    {
                        SetRefractionMaskLayer(Refraction.GetValidRefractionMaskLayer());
                    }

                    ExecuteRendering(Refraction, _g2dwCamera, _wholeWaterVisibleArea, backgroundColor, _allowHDR, _allowMSAA);
                    materialModule.SetRefractionRenderTexture(Refraction.RenderTexture);
                }

                if (renderReflection)
                {
                    _refractionMask.SetActive(false);

                    ExecuteRendering(Reflection, _g2dwCamera, _wholeWaterVisibleArea, _clearColor, _allowHDR, _allowMSAA);
                    materialModule.SetReflectionRenderTexture(Reflection.RenderTexture);
                }
            }
            else
            {
                if (renderRefraction)
                {
                    int extraLayersToIgnoreMask = RefractionPartiallySubmergedObjects.CullingMask;

                    if (!isUsingOpaqueRenderQueue)
                    {
                        SetRefractionMaskLayer(Refraction.GetValidRefractionMaskLayer(extraLayersToIgnoreMask));
                    }

                    ExecuteRendering(Refraction, _g2dwCamera, _wholeWaterVisibleArea, backgroundColor, _allowHDR, _allowMSAA, extraLayersToIgnoreMask);
                    materialModule.SetRefractionRenderTexture(Refraction.RenderTexture);

                    if (!isUsingOpaqueRenderQueue)
                    {
                        SetRefractionMaskLayer(RefractionPartiallySubmergedObjects.GetValidRefractionMaskLayer());
                    }

                    ExecuteRendering(RefractionPartiallySubmergedObjects, _g2dwCamera, _wholeWaterVisibleArea, _clearColor, _allowHDR, _allowMSAA);
                    materialModule.SetRefractionPartiallySubmergedObjectsRenderTexture(RefractionPartiallySubmergedObjects.RenderTexture);
                }
                if (renderReflection)
                {
                    _refractionMask.SetActive(false);

                    ExecuteRendering(Reflection, _g2dwCamera, _surfaceVisibleArea, _clearColor, _allowHDR, _allowMSAA, ReflectionPartiallySubmergedObjects.CullingMask);
                    materialModule.SetReflectionRenderTexture(Reflection.RenderTexture);

                    ExecuteRendering(ReflectionPartiallySubmergedObjects, _g2dwCamera, _surfaceBelowSubmergeLevelVisibleArea, _clearColor, _allowHDR, _allowMSAA);
                    materialModule.SetReflectionPartiallySubmergedObjectsRenderTexture(ReflectionPartiallySubmergedObjects.RenderTexture);
                }
            }

            _refractionMask.SetActive(false);

#if !GAME_2D_WATER_KIT_LWRP && !GAME_2D_WATER_KIT_URP
            QualitySettings.pixelLightCount = pixelLightCount;
#endif

            _meshModule.SetRendererActive(true);

            var worldToVisibleAreaMatrix = Matrix4x4.TRS(_wholeWaterVisibleArea.RefractionProperties.Position, _wholeWaterVisibleArea.RefractionProperties.Rotation, new Vector3(1f, 1f, -1f)).inverse;
            var projectionMatrix         = _wholeWaterVisibleArea.RefractionProperties.ProjectionMatrix;
            materialModule.SetWaterMatrix(projectionMatrix * worldToVisibleAreaMatrix * _mainModule.LocalToWorldMatrix);
            materialModule.SetReflectionLowerLimit(_mainModule.Height * 0.5f);
            materialModule.ValidateMaterialPropertyBlock();

            if (isConnectedToLargeWaterArea)
            {
                SetCurrentFrameRenderInformationToLargeWaterAreaManager(largeWaterAreaManager, renderRefraction, renderReflection, projectionMatrix, worldToVisibleAreaMatrix, renderingCameraInformation.CurrentCamera);
            }
        }
 internal override void Render(UnityEngine.Rendering.ScriptableRenderContext context, RenderingCameraInformation renderingCameraInformation)
示例#7
0
 internal abstract void Render(RenderingCameraInformation renderingCameraInformation);
示例#8
0
 internal abstract void Render(UnityEngine.Rendering.ScriptableRenderContext context, RenderingCameraInformation renderingCameraInformation);
示例#9
0
 internal abstract bool Setup(RenderingCameraInformation renderingCameraInformation);