Exemple #1
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);
        }
Exemple #2
0
        int RenderBuiltins(PostProcessRenderContext context, bool isFinalPass, int releaseTargetAfterUse = -1)
        {
            var uberSheet = context.propertySheets.Get(context.resources.shaders.uber);

            uberSheet.ClearKeywords();
            uberSheet.properties.Clear();
            context.uberSheet           = uberSheet;
            context.autoExposureTexture = RuntimeUtilities.whiteTexture;

            var cmd = context.command;

            cmd.BeginSample("BuiltinStack");

            int tempTarget       = -1;
            var finalDestination = context.destination;

            if (!isFinalPass)
            {
                // Render to an intermediate target as this won't be the final pass
                tempTarget = m_TargetPool.Get();
                cmd.GetTemporaryRT(tempTarget, context.width, context.height, 24, FilterMode.Bilinear, context.sourceFormat);
                context.destination = tempTarget;

                // Handle FXAA's keep alpha mode
                if (antialiasingMode == Antialiasing.FastApproximateAntialiasing && !fastApproximateAntialiasing.keepAlpha)
                {
                    uberSheet.properties.SetFloat(ShaderIDs.LumaInAlpha, 1f);
                }
            }

            // Depth of field final combination pass used to be done in Uber which led to artifacts
            // when used at the same time as Bloom (because both effects used the same source, so
            // the stronger bloom was, the more DoF was eaten away in out of focus areas)
            int depthOfFieldTarget = RenderEffect <DepthOfField>(context, true);

            // Motion blur is a separate pass - could potentially be done after DoF depending on the
            // kind of results you're looking for...
            int motionBlurTarget = RenderEffect <MotionBlur>(context, true);

            // Prepare exposure histogram if needed
            if (ShouldGenerateLogHistogram(context))
            {
                m_LogHistogram.Generate(context);
            }

            // Uber effects
            RenderEffect <AutoExposure>(context);
            uberSheet.properties.SetTexture(ShaderIDs.AutoExposureTex, context.autoExposureTexture);

            RenderEffect <ChromaticAberration>(context);
            RenderEffect <Bloom>(context);
            RenderEffect <Vignette>(context);
            RenderEffect <Grain>(context);

            if (!breakBeforeColorGrading)
            {
                RenderEffect <ColorGrading>(context);
            }

            int pass = 0;

            if (isFinalPass)
            {
                uberSheet.EnableKeyword("FINALPASS");
                dithering.Render(context);

                if (context.flip && !context.isSceneView)
                {
                    pass = 1;
                }
            }

            cmd.BlitFullscreenTriangle(context.source, context.destination, uberSheet, pass);

            context.source      = context.destination;
            context.destination = finalDestination;

            if (releaseTargetAfterUse > -1)
            {
                cmd.ReleaseTemporaryRT(releaseTargetAfterUse);
            }
            if (motionBlurTarget > -1)
            {
                cmd.ReleaseTemporaryRT(motionBlurTarget);
            }
            if (depthOfFieldTarget > -1)
            {
                cmd.ReleaseTemporaryRT(motionBlurTarget);
            }

            cmd.EndSample("BuiltinStack");

            return(tempTarget);
        }
Exemple #3
0
        int RenderBuiltins(PostProcessRenderContext context, bool isFinalPass, int releaseTargetAfterUse = -1, int eye = -1)
        {
            var uberSheet = context.propertySheets.Get(context.resources.shaders.uber);

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

            if (isFinalPass && context.stereoActive && context.stereoRenderingMode == PostProcessRenderContext.StereoRenderingMode.SinglePassInstanced)
            {
                uberSheet.EnableKeyword("STEREO_INSTANCING_ENABLED");
            }

            var cmd = context.command;

            cmd.BeginSample("BuiltinStack");

            int tempTarget       = -1;
            var finalDestination = context.destination;

            if (!isFinalPass)
            {
                // Render to an intermediate target as this won't be the final pass
                tempTarget = m_TargetPool.Get();
                context.GetScreenSpaceTemporaryRT(cmd, tempTarget, 0, context.sourceFormat);
                context.destination = tempTarget;

                // Handle FXAA's keep alpha mode
                if (antialiasingMode == Antialiasing.FastApproximateAntialiasing && !fastApproximateAntialiasing.keepAlpha)
                {
                    uberSheet.properties.SetFloat(ShaderIDs.LumaInAlpha, 1f);
                }
            }

            // Depth of field final combination pass used to be done in Uber which led to artifacts
            // when used at the same time as Bloom (because both effects used the same source, so
            // the stronger bloom was, the more DoF was eaten away in out of focus areas)
            int depthOfFieldTarget = RenderEffect <DepthOfField>(context, true);

            // Motion blur is a separate pass - could potentially be done after DoF depending on the
            // kind of results you're looking for...
            int motionBlurTarget = RenderEffect <MotionBlur>(context, true);

            // Prepare exposure histogram if needed
            if (ShouldGenerateLogHistogram(context))
            {
                m_LogHistogram.Generate(context);
            }

            // Uber effects
            RenderEffect <AutoExposure>(context);
            uberSheet.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)
            {
                uberSheet.EnableKeyword("FINALPASS");
                dithering.Render(context);
                ApplyFlip(context, uberSheet.properties);
            }
            else
            {
                ApplyDefaultFlip(uberSheet.properties);
            }

            if (context.stereoActive && context.stereoRenderingMode == PostProcessRenderContext.StereoRenderingMode.SinglePassInstanced)
            {
                uberSheet.properties.SetInt(ShaderIDs.DepthSlice, eye);
                cmd.BlitFullscreenTriangleToTexArray(context.source, context.destination, uberSheet, 0, false, eye);
            }
            else
            {
                cmd.BlitFullscreenTriangle(context.source, context.destination, uberSheet, 0);
            }

            context.source      = context.destination;
            context.destination = finalDestination;

            if (releaseTargetAfterUse > -1)
            {
                cmd.ReleaseTemporaryRT(releaseTargetAfterUse);
            }
            if (motionBlurTarget > -1)
            {
                cmd.ReleaseTemporaryRT(motionBlurTarget);
            }
            if (depthOfFieldTarget > -1)
            {
                cmd.ReleaseTemporaryRT(depthOfFieldTarget);
            }
            if (context.bloomBufferNameID > -1)
            {
                cmd.ReleaseTemporaryRT(context.bloomBufferNameID);
            }

            cmd.EndSample("BuiltinStack");

            return(tempTarget);
        }