Пример #1
0
    private void OnRenderImage(RenderTexture iSource, RenderTexture iDestination)
    {
        if (renderSettings.doubleFrameRenderingMode)
        {
            if (mDoubleFrameRendererSwitch)
            {
                var _blitMaterial = materialContainer.blitMaterial;
                _blitMaterial.SetVector("_LightTransform", mlightPPRT.GetTransformation(mMainCamera));
                _blitMaterial.SetVector("_OcclusionTransform", floorOcclusionMask.GetTransformation(mMainCamera));

                Graphics.Blit(iSource, iDestination, _blitMaterial);

                mDoubleFrameRendererSwitch = false;
                return;
            }

            mDoubleFrameRendererSwitch = true;
        }

        if (materialContainer.blitMaterial == null)
        {
            Debug.Log($"FovSystemManager: Unable to blit Fov mask. {nameof(materialContainer.blitMaterial)} not provided.");
            return;
        }

        if (objectOcclusionMask == null)
        {
            Graphics.Blit(iSource, iDestination);
            return;
        }

        using (new DisposableProfiler("5. Light Mask Render (No Gfx Time)"))
        {
            mlightPPRT = mLightMaskRenderer.Render(
                mMainCamera,
                operationParameters.lightPPRTParameter,
                floorOcclusionMask,
                renderSettings,
                matrixRotationMode);
        }

        using (new DisposableProfiler("6. Generate Obstacle Light Mask"))
        {
            mPostProcessingStack.CreateWallLightMask(
                mlightPPRT,
                obstacleLightMask,
                renderSettings,
                operationParameters.cameraOrthographicSize);
        }

        // Debug View Selection.
        if (renderSettings.viewMode == RenderSettings.ViewMode.LightLayer)
        {
            PixelPerfectRT.Transform(mlightPPRT, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.WallLayer)
        {
            PixelPerfectRT.Transform(obstacleLightMask, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.FovObjectOcclusion)
        {
            PixelPerfectRT.Transform(objectOcclusionMask, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.FovFloorOcclusion)
        {
            PixelPerfectRT.Transform(floorOcclusionMask, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.FovWallAndFloorOcclusion)
        {
            PixelPerfectRT.Transform(wallFloorOcclusionMask, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.Obstacle)
        {
            PixelPerfectRT.Transform(mOcclusionPPRT, iDestination, mMainCamera, materialContainer);

            return;
        }

        using (new DisposableProfiler("7. Light Mask Blur"))
        {
            mPostProcessingStack.BlurLightMask(mlightPPRT.renderTexture, renderSettings, operationParameters.cameraOrthographicSize, mMatrixRotationModeBlend);
        }

        RenderTexture _backgroundMask = null;

        using (new DisposableProfiler("8. Render Background"))
        {
            _backgroundMask = mBackgroundRenderer.Render(renderSettings);
        }

        // Debug Views Selection.
        if (renderSettings.viewMode == RenderSettings.ViewMode.LightLayerBlurred)
        {
            PixelPerfectRT.Transform(mlightPPRT, iDestination, mMainCamera, materialContainer);

            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.Background)
        {
            Graphics.Blit(_backgroundMask, iDestination);

            return;
        }

        using (new DisposableProfiler("9. Blit Scene with Mixed Lights"))
        {
            mlightPPRT.renderTexture.filterMode         = FilterMode.Bilinear;
            obstacleLightMask.renderTexture.filterMode  = FilterMode.Bilinear;
            floorOcclusionMask.renderTexture.filterMode = matrixRotationMode ? FilterMode.Bilinear : FilterMode.Point;

            var _blitMaterial = materialContainer.blitMaterial;
            _blitMaterial.SetTexture("_LightMask", mlightPPRT.renderTexture);
            _blitMaterial.SetTexture("_OcclusionMask", floorOcclusionMask.renderTexture);
            _blitMaterial.SetTexture("_ObstacleLightMask", obstacleLightMask.renderTexture);
            _blitMaterial.SetVector("_LightTransform", mlightPPRT.GetTransformation(mMainCamera));
            _blitMaterial.SetVector("_OcclusionTransform", floorOcclusionMask.GetTransformation(mMainCamera));

            _blitMaterial.SetTexture("_BackgroundTex", _backgroundMask);
            _blitMaterial.SetVector("_AmbLightBloomSA", new Vector4(renderSettings.ambient, renderSettings.lightMultiplier, renderSettings.bloomSensitivity, renderSettings.bloomAdd));
            _blitMaterial.SetFloat("_BackgroundMultiplier", renderSettings.backgroundMultiplier);

            Graphics.Blit(iSource, iDestination, _blitMaterial);
        }
    }
Пример #2
0
    private void OnRenderImage(RenderTexture iSource, RenderTexture iDestination)
    {
        if (materialContainer.blitMaterial == null)
        {
            Debug.Log($"FovSystemManager: Unable to blit Fov mask. {nameof(materialContainer.blitMaterial)} not provided.");
            return;
        }

        if (globalOcclusionMask == null)
        {
            Graphics.Blit(iSource, iDestination);
            return;
        }

        RenderTexture _lightMask = null;

        using (new DisposableProfiler("5. Light Mask Render (No Gfx Time)"))
        {
            _lightMask = mLightMaskRenderer.Render(renderSettings);
        }

        using (new DisposableProfiler("6. Generate Obstacle Light Mask"))
        {
            mPostProcessingStack.CreateWallLightMask(_lightMask, obstacleLightMask, renderSettings, mCurrentMaskParameters.cameraOrthographicSize);
        }

        // Debug View Selection.
        if (renderSettings.viewMode == RenderSettings.ViewMode.LightLayer)
        {
            Graphics.Blit(_lightMask, iDestination);
            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.WallLayer)
        {
            Graphics.Blit(obstacleLightMask, iDestination);
            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.FovObstacle)
        {
            Graphics.Blit(globalOcclusionMask, iDestination);
            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.FovObstacleExtended)
        {
            Graphics.Blit(occlusionMaskExtended, iDestination);
            return;
        }

        using (new DisposableProfiler("7. Light Mask Blur"))
        {
            mPostProcessingStack.BlurLightMask(_lightMask, renderSettings, mCurrentMaskParameters.cameraOrthographicSize);
        }

        using (new DisposableProfiler("8. Mix Light Masks"))
        {
            // Mix Fov and Light masks.
            var _fovLightMixMaterial = materialContainer.MaskMixerMaterial;
            _fovLightMixMaterial.SetTexture("_LightMask", _lightMask);
            _fovLightMixMaterial.SetTexture("_OcclusionMask", globalOcclusionMask);
            _fovLightMixMaterial.SetTexture("_ObstacleLightMask", obstacleLightMask);

            if (globalOcclusionMask != null)
            {
                _fovLightMixMaterial.SetFloat("_OcclusionUVAdjustment", RenderSettings.GetOcclusionUvAdjustment(_lightMask.width));
            }

            Graphics.Blit(null, mixedLightMask, _fovLightMixMaterial);
        }

        RenderTexture _backgroundMask = null;

        using (new DisposableProfiler("9. Render Background"))
        {
            _backgroundMask = mBackgroundRenderer.Render(renderSettings);
        }

        // Debug Views Selection.
        if (renderSettings.viewMode == RenderSettings.ViewMode.LightMix)
        {
            Graphics.Blit(mixedLightMask, iDestination);
            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.LightLayerBlurred)
        {
            Graphics.Blit(_lightMask, iDestination);
            return;
        }
        else if (renderSettings.viewMode == RenderSettings.ViewMode.Background)
        {
            Graphics.Blit(_backgroundMask, iDestination);
            return;
        }

        using (new DisposableProfiler("10. Blit Scene with Mixed Lights"))
        {
            var _blitMaterial = materialContainer.blitMaterial;
            _blitMaterial.SetTexture("_LightTex", mixedLightMask);
            _blitMaterial.SetTexture("_BackgroundTex", _backgroundMask);
            _blitMaterial.SetVector("_AmbLightBloomSA", new Vector4(renderSettings.ambient, renderSettings.lightMultiplier, renderSettings.bloomSensitivity, renderSettings.bloomAdd));
            _blitMaterial.SetFloat("_BackgroundMultiplier", renderSettings.backgroundMultiplier);

            Graphics.Blit(iSource, iDestination, _blitMaterial);
        }
    }