void DoLazyInitialization(PostProcessRenderContext context)
        {
            var shader = context.resources.shaders.multiScaleAO;

            m_PropertySheet = context.propertySheets.Get(shader);
            m_PropertySheet.ClearKeywords();

            // Render texture handles
            if (m_Result == null)
            {
                m_DepthCopy   = new RTHandle("DepthCopy", TextureType.Float, MipLevel.Original);
                m_LinearDepth = new RTHandle("LinearDepth", TextureType.HalfUAV, MipLevel.Original);

                m_LowDepth1 = new RTHandle("LowDepth1", TextureType.FloatUAV, MipLevel.L1);
                m_LowDepth2 = new RTHandle("LowDepth2", TextureType.FloatUAV, MipLevel.L2);
                m_LowDepth3 = new RTHandle("LowDepth3", TextureType.FloatUAV, MipLevel.L3);
                m_LowDepth4 = new RTHandle("LowDepth4", TextureType.FloatUAV, MipLevel.L4);

                m_TiledDepth1 = new RTHandle("TiledDepth1", TextureType.HalfTiledUAV, MipLevel.L3);
                m_TiledDepth2 = new RTHandle("TiledDepth2", TextureType.HalfTiledUAV, MipLevel.L4);
                m_TiledDepth3 = new RTHandle("TiledDepth3", TextureType.HalfTiledUAV, MipLevel.L5);
                m_TiledDepth4 = new RTHandle("TiledDepth4", TextureType.HalfTiledUAV, MipLevel.L6);

                m_Occlusion1 = new RTHandle("Occlusion1", TextureType.FixedUAV, MipLevel.L1);
                m_Occlusion2 = new RTHandle("Occlusion2", TextureType.FixedUAV, MipLevel.L2);
                m_Occlusion3 = new RTHandle("Occlusion3", TextureType.FixedUAV, MipLevel.L3);
                m_Occlusion4 = new RTHandle("Occlusion4", TextureType.FixedUAV, MipLevel.L4);

                m_Combined1 = new RTHandle("Combined1", TextureType.FixedUAV, MipLevel.L1);
                m_Combined2 = new RTHandle("Combined2", TextureType.FixedUAV, MipLevel.L2);
                m_Combined3 = new RTHandle("Combined3", TextureType.FixedUAV, MipLevel.L3);

                m_Result = new RTHandle("AmbientOcclusion", TextureType.FixedUAV, MipLevel.Original);
            }
        }
Exemple #2
0
        private void PreparePropertySheet(PostProcessRenderContext context)
        {
            PropertySheet propertySheet = context.propertySheets.Get(m_Resources.shaders.multiScaleAO);

            propertySheet.ClearKeywords();
            propertySheet.properties.SetVector(ShaderIDs.AOColor, Color.white - m_Settings.color.value);
            m_PropertySheet = propertySheet;
        }
Exemple #3
0
        internal void Render(PostProcessRenderContext context)
        {
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.deferredFog);

            propertySheet.ClearKeywords();
            Color c = (!RuntimeUtilities.isLinearColorSpace) ? RenderSettings.fogColor : RenderSettings.fogColor.linear;

            propertySheet.properties.SetVector(ShaderIDs.FogColor, c);
            propertySheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
            CommandBuffer command = context.command;

            command.BlitFullscreenTriangle(context.source, context.destination, propertySheet, excludeSkybox ? 1 : 0);
        }
Exemple #4
0
        private void RenderFinalPass(PostProcessRenderContext context, int releaseTargetAfterUse = -1)
        {
            CommandBuffer command = context.command;

            command.BeginSample("FinalPass");
            if (breakBeforeColorGrading)
            {
                PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.discardAlpha);
                command.BlitFullscreenTriangle(context.source, context.destination, propertySheet, 0);
            }
            else
            {
                PropertySheet propertySheet2 = context.propertySheets.Get(context.resources.shaders.finalPass);
                propertySheet2.ClearKeywords();
                propertySheet2.properties.Clear();
                context.uberSheet = propertySheet2;
                int num = -1;
                if (antialiasingMode == Antialiasing.FastApproximateAntialiasing)
                {
                    propertySheet2.EnableKeyword((!fastApproximateAntialiasing.fastMode) ? "FXAA" : "FXAA_LOW");
                    if (fastApproximateAntialiasing.keepAlpha)
                    {
                        propertySheet2.EnableKeyword("FXAA_KEEP_ALPHA");
                    }
                }
                else if (antialiasingMode == Antialiasing.SubpixelMorphologicalAntialiasing && subpixelMorphologicalAntialiasing.IsSupported())
                {
                    num = m_TargetPool.Get();
                    RenderTargetIdentifier destination = context.destination;
                    context.GetScreenSpaceTemporaryRT(context.command, num, 0, context.sourceFormat);
                    context.destination = num;
                    subpixelMorphologicalAntialiasing.Render(context);
                    context.source      = num;
                    context.destination = destination;
                }
                dithering.Render(context);
                ApplyFlip(context, propertySheet2.properties);
                command.BlitFullscreenTriangle(context.source, context.destination, propertySheet2, 0);
                if (num > -1)
                {
                    command.ReleaseTemporaryRT(num);
                }
            }
            if (releaseTargetAfterUse > -1)
            {
                command.ReleaseTemporaryRT(releaseTargetAfterUse);
            }
            command.EndSample("FinalPass");
        }
Exemple #5
0
        private void Render(PostProcessRenderContext context, CommandBuffer cmd, int occlusionSource)
        {
            DoLazyInitialization(context);
            m_Settings.radius.value = Mathf.Max(m_Settings.radius.value, 0.0001f);
            bool          flag          = m_Settings.quality.value < AmbientOcclusionQuality.High;
            float         value         = m_Settings.intensity.value;
            float         value2        = m_Settings.radius.value;
            float         z             = (!flag) ? 1f : 0.5f;
            float         w             = m_SampleCount[(int)m_Settings.quality.value];
            PropertySheet propertySheet = m_PropertySheet;

            propertySheet.ClearKeywords();
            propertySheet.properties.SetVector(ShaderIDs.AOParams, new Vector4(value, value2, z, w));
            propertySheet.properties.SetVector(ShaderIDs.AOColor, Color.white - m_Settings.color.value);
            if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog)
            {
                propertySheet.EnableKeyword("APPLY_FORWARD_FOG");
                propertySheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
            }
            int num = (!flag) ? 1 : 2;
            int occlusionTexture = ShaderIDs.OcclusionTexture1;
            int widthOverride    = context.width / num;
            int heightOverride   = context.height / num;

            context.GetScreenSpaceTemporaryRT(cmd, occlusionTexture, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, FilterMode.Bilinear, widthOverride, heightOverride);
            cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, occlusionTexture, propertySheet, occlusionSource);
            int occlusionTexture2 = ShaderIDs.OcclusionTexture2;

            context.GetScreenSpaceTemporaryRT(cmd, occlusionTexture2, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            cmd.BlitFullscreenTriangle(occlusionTexture, occlusionTexture2, propertySheet, 2 + occlusionSource);
            cmd.ReleaseTemporaryRT(occlusionTexture);
            cmd.BlitFullscreenTriangle(occlusionTexture2, m_Result, propertySheet, 4);
            cmd.ReleaseTemporaryRT(occlusionTexture2);
            if (context.IsDebugOverlayEnabled(DebugOverlay.AmbientOcclusion))
            {
                context.PushDebugOverlay(cmd, m_Result, propertySheet, 7);
            }
        }
 internal void RenderSpecialOverlays(PostProcessRenderContext context)
 {
     if (debugOverlay == DebugOverlay.Depth)
     {
         PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.debugOverlays);
         propertySheet.properties.SetVector(ShaderIDs.Params, new Vector4((!overlaySettings.linearDepth) ? 0f : 1f, 0f, 0f, 0f));
         PushDebugOverlay(context.command, BuiltinRenderTextureType.None, propertySheet, 0);
     }
     else if (debugOverlay == DebugOverlay.Normals)
     {
         PropertySheet propertySheet2 = context.propertySheets.Get(context.resources.shaders.debugOverlays);
         propertySheet2.ClearKeywords();
         if (context.camera.actualRenderingPath == RenderingPath.DeferredLighting)
         {
             propertySheet2.EnableKeyword("SOURCE_GBUFFER");
         }
         PushDebugOverlay(context.command, BuiltinRenderTextureType.None, propertySheet2, 1);
     }
     else if (debugOverlay == DebugOverlay.MotionVectors)
     {
         PropertySheet propertySheet3 = context.propertySheets.Get(context.resources.shaders.debugOverlays);
         propertySheet3.properties.SetVector(ShaderIDs.Params, new Vector4(overlaySettings.motionColorIntensity, overlaySettings.motionGridSize, 0f, 0f));
         PushDebugOverlay(context.command, context.source, propertySheet3, 2);
     }
     else if (debugOverlay == DebugOverlay.NANTracker)
     {
         PropertySheet sheet = context.propertySheets.Get(context.resources.shaders.debugOverlays);
         PushDebugOverlay(context.command, context.source, sheet, 3);
     }
     else if (debugOverlay == DebugOverlay.ColorBlindnessSimulation)
     {
         PropertySheet propertySheet4 = context.propertySheets.Get(context.resources.shaders.debugOverlays);
         propertySheet4.properties.SetVector(ShaderIDs.Params, new Vector4(overlaySettings.colorBlindnessStrength, 0f, 0f, 0f));
         PushDebugOverlay(context.command, context.source, propertySheet4, (int)(4 + overlaySettings.colorBlindnessType));
     }
 }
Exemple #7
0
        internal override void Render(PostProcessRenderContext context)
        {
            CheckOutput(width, height);
            LogHistogram  logHistogram  = context.logHistogram;
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.lightMeter);

            propertySheet.ClearKeywords();
            propertySheet.properties.SetBuffer(ShaderIDs.HistogramBuffer, logHistogram.data);
            Vector4 histogramScaleOffsetRes = logHistogram.GetHistogramScaleOffsetRes(context);

            histogramScaleOffsetRes.z = 1f / (float)width;
            histogramScaleOffsetRes.w = 1f / (float)height;
            propertySheet.properties.SetVector(ShaderIDs.ScaleOffsetRes, histogramScaleOffsetRes);
            if (context.logLut != null && showCurves)
            {
                propertySheet.EnableKeyword("COLOR_GRADING_HDR");
                propertySheet.properties.SetTexture(ShaderIDs.Lut3D, context.logLut);
            }
            AutoExposure autoExposure = context.autoExposure;

            if (autoExposure != null)
            {
                float x = autoExposure.filtering.value.x;
                float y = autoExposure.filtering.value.y;
                y = Mathf.Clamp(y, 1.01f, 99f);
                x = Mathf.Clamp(x, 1f, y - 0.01f);
                Vector4 value = new Vector4(x * 0.01f, y * 0.01f, RuntimeUtilities.Exp2(autoExposure.minLuminance.value), RuntimeUtilities.Exp2(autoExposure.maxLuminance.value));
                propertySheet.EnableKeyword("AUTO_EXPOSURE");
                propertySheet.properties.SetVector(ShaderIDs.Params, value);
            }
            CommandBuffer command = context.command;

            command.BeginSample("LightMeter");
            command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, base.output, propertySheet, 0);
            command.EndSample("LightMeter");
        }
Exemple #8
0
        private int RenderBuiltins(PostProcessRenderContext context, bool isFinalPass, int releaseTargetAfterUse = -1)
        {
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.uber);

            propertySheet.ClearKeywords();
            propertySheet.properties.Clear();
            context.uberSheet           = propertySheet;
            context.autoExposureTexture = RuntimeUtilities.whiteTexture;
            context.bloomBufferNameID   = -1;
            CommandBuffer command = context.command;

            command.BeginSample("BuiltinStack");
            int num = -1;
            RenderTargetIdentifier destination = context.destination;

            if (!isFinalPass)
            {
                num = m_TargetPool.Get();
                context.GetScreenSpaceTemporaryRT(command, num, 0, context.sourceFormat);
                context.destination = num;
                if (antialiasingMode == Antialiasing.FastApproximateAntialiasing && !fastApproximateAntialiasing.keepAlpha)
                {
                    propertySheet.properties.SetFloat(ShaderIDs.LumaInAlpha, 1f);
                }
            }
            int num2 = RenderEffect <DepthOfField>(context, useTempTarget: true);
            int num3 = RenderEffect <MotionBlur>(context, useTempTarget: true);

            if (ShouldGenerateLogHistogram(context))
            {
                m_LogHistogram.Generate(context);
            }
            RenderEffect <AutoExposure>(context);
            propertySheet.properties.SetTexture(ShaderIDs.AutoExposureTex, context.autoExposureTexture);
            RenderEffect <LensDistortion>(context);
            RenderEffect <ChromaticAberration>(context);
            RenderEffect <Bloom>(context);
            RenderEffect <Vignette>(context);
            RenderEffect <Grain>(context);
            if (!breakBeforeColorGrading)
            {
                RenderEffect <ColorGrading>(context);
            }
            if (isFinalPass)
            {
                propertySheet.EnableKeyword("FINALPASS");
                dithering.Render(context);
                ApplyFlip(context, propertySheet.properties);
            }
            else
            {
                ApplyDefaultFlip(propertySheet.properties);
            }
            command.BlitFullscreenTriangle(context.source, context.destination, propertySheet, 0);
            context.source      = context.destination;
            context.destination = destination;
            if (releaseTargetAfterUse > -1)
            {
                command.ReleaseTemporaryRT(releaseTargetAfterUse);
            }
            if (num3 > -1)
            {
                command.ReleaseTemporaryRT(num3);
            }
            if (num2 > -1)
            {
                command.ReleaseTemporaryRT(num2);
            }
            if (context.bloomBufferNameID > -1)
            {
                command.ReleaseTemporaryRT(context.bloomBufferNameID);
            }
            command.EndSample("BuiltinStack");
            return(num);
        }