Beispiel #1
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");
        }
        public void RenderAfterOpaque(PostProcessRenderContext context)
        {
            var cmd = context.command;

            cmd.BeginSample("Ambient Occlusion");
            SetResources(context.resources);
            PreparePropertySheet(context);
            CheckAOTexture(context);

            // In Forward mode, fog is applied at the object level in the grometry pass so we need
            // to apply it to AO as well or it'll drawn on top of the fog effect.
            if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog)
            {
                m_PropertySheet.EnableKeyword("APPLY_FORWARD_FOG");
                m_PropertySheet.properties.SetVector(
                    ShaderIDs.FogParams,
                    new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance)
                    );
            }

            GenerateAOMap(cmd, context.camera, m_AmbientOnlyAO, null, false);
            PushDebug(context);
            cmd.SetGlobalTexture(ShaderIDs.MSVOcclusionTexture, m_AmbientOnlyAO);
            cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CameraTarget, m_PropertySheet, (int)Pass.CompositionForward);
            cmd.EndSample("Ambient Occlusion");
        }
Beispiel #3
0
        /// <summary>
        /// Blits a fullscreen triangle to a double-wide destination.
        /// </summary>
        /// <param name="cmd">The command buffer to use</param>
        /// <param name="source">The source render target</param>
        /// <param name="destination">The destination render target</param>
        /// <param name="propertySheet">The property sheet to use</param>
        /// <param name="pass">The pass from the material to use</param>
        /// <param name="eye">The target eye</param>
        public static void BlitFullscreenTriangleToDoubleWide(this CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, PropertySheet propertySheet, int pass, int eye)
        {
            Vector4 posScaleOffset = new Vector4(0.5f, 1.0f, -0.5f, 0);

            if (eye == 1)
            {
                posScaleOffset.z = 0.5f;
            }
            propertySheet.EnableKeyword("STEREO_DOUBLEWIDE_TARGET");
            propertySheet.properties.SetVector(ShaderIDs.PosScaleOffset, posScaleOffset);
            cmd.BlitFullscreenTriangle(source, destination, propertySheet, 0);
        }
Beispiel #4
0
        public override void Render(PostProcessRenderContext context)
        {
            PropertySheet uberSheet = context.uberSheet;
            float         val       = 1.6f * Math.Max(Mathf.Abs(base.settings.intensity.value), 1f);
            float         num       = (float)Math.PI / 180f * Math.Min(160f, val);
            float         y         = 2f * Mathf.Tan(num * 0.5f);
            Vector4       value     = new Vector4(base.settings.centerX.value, base.settings.centerY.value, Mathf.Max(base.settings.intensityX.value, 0.0001f), Mathf.Max(base.settings.intensityY.value, 0.0001f));
            Vector4       value2    = new Vector4((!(base.settings.intensity.value >= 0f)) ? (1f / num) : num, y, 1f / base.settings.scale.value, base.settings.intensity.value);

            uberSheet.EnableKeyword("DISTORT");
            uberSheet.properties.SetVector(ShaderIDs.Distortion_CenterScale, value);
            uberSheet.properties.SetVector(ShaderIDs.Distortion_Amount, value2);
        }
Beispiel #5
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");
        }
Beispiel #6
0
        public void RenderAfterOpaque(PostProcessRenderContext context)
        {
            CommandBuffer command = context.command;

            command.BeginSample("Ambient Occlusion");
            SetResources(context.resources);
            PreparePropertySheet(context);
            CheckAOTexture(context);
            if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog)
            {
                m_PropertySheet.EnableKeyword("APPLY_FORWARD_FOG");
                m_PropertySheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
            }
            GenerateAOMap(command, context.camera, m_AmbientOnlyAO, null, invert: false, isMSAA: false);
            PushDebug(context);
            command.SetGlobalTexture(ShaderIDs.MSVOcclusionTexture, m_AmbientOnlyAO);
            command.BlitFullscreenTriangle(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CameraTarget, m_PropertySheet, 2, RenderBufferLoadAction.Load);
            command.EndSample("Ambient Occlusion");
        }
Beispiel #7
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));
     }
 }
Beispiel #9
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);
        }