From 695c09e8ff6b166cf6afd58f03c0fcaf2e863886 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 29 May 2023 18:41:51 +0200 Subject: [PATCH] Added a custom effect injection point right before upscaling & TAA, to be rendered at the lower internal rendering resolution. --- .../PostProcessing/Runtime/PostProcessEvent.cs | 13 +++++++++++-- .../PostProcessing/Runtime/PostProcessLayer.cs | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessEvent.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessEvent.cs index 22ec277..beb55b3 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessEvent.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessEvent.cs @@ -9,20 +9,29 @@ namespace UnityEngine.Rendering.PostProcessing { /// /// Effects at this injection points will execute before transparent objects are rendered. + /// These effects will be rendered at the internal render resolution. /// BeforeTransparent = 0, + /// + /// Effects at this injection point will execute before upscaling and temporal anti-aliasing. + /// These effects will be rendered at the internal render resolution. + /// + BeforeUpscaling = 1, + /// /// Effects at this injection points will execute after temporal anti-aliasing and before /// builtin effects are rendered. + /// These effects will be rendered at the display resolution. /// - BeforeStack = 1, + BeforeStack = 2, /// /// Effects at this injection points will execute after builtin effects have been rendered /// and before the final pass that does FXAA and applies dithering. + /// These effects will be rendered at the display resolution. /// - AfterStack = 2, + AfterStack = 3, } // Box free comparer for our `PostProcessEvent` enum, else the runtime will box the type when diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs index 354ea14..2655935 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs @@ -173,6 +173,9 @@ namespace UnityEngine.Rendering.PostProcessing [SerializeField] List m_BeforeTransparentBundles; + [SerializeField] + List m_BeforeUpscalingBundles; + [SerializeField] List m_BeforeStackBundles; @@ -314,6 +317,7 @@ namespace UnityEngine.Rendering.PostProcessing // Create these lists only once, the serialization system will take over after that RuntimeUtilities.CreateIfNull(ref m_BeforeTransparentBundles); + RuntimeUtilities.CreateIfNull(ref m_BeforeUpscalingBundles); RuntimeUtilities.CreateIfNull(ref m_BeforeStackBundles); RuntimeUtilities.CreateIfNull(ref m_AfterStackBundles); @@ -329,6 +333,7 @@ namespace UnityEngine.Rendering.PostProcessing // Update sorted lists with newly added or removed effects in the assemblies UpdateBundleSortList(m_BeforeTransparentBundles, PostProcessEvent.BeforeTransparent); + UpdateBundleSortList(m_BeforeUpscalingBundles, PostProcessEvent.BeforeUpscaling); UpdateBundleSortList(m_BeforeStackBundles, PostProcessEvent.BeforeStack); UpdateBundleSortList(m_AfterStackBundles, PostProcessEvent.AfterStack); @@ -336,6 +341,7 @@ namespace UnityEngine.Rendering.PostProcessing sortedBundles = new Dictionary>(new PostProcessEventComparer()) { { PostProcessEvent.BeforeTransparent, m_BeforeTransparentBundles }, + { PostProcessEvent.BeforeUpscaling, m_BeforeUpscalingBundles }, { PostProcessEvent.BeforeStack, m_BeforeStackBundles }, { PostProcessEvent.AfterStack, m_AfterStackBundles } }; @@ -1055,6 +1061,10 @@ namespace UnityEngine.Rendering.PostProcessing } context.source = lastTarget; } + + // Right before upscaling & temporal anti-aliasing + if (HasActiveEffects(PostProcessEvent.BeforeUpscaling, context)) + lastTarget = RenderInjectionPoint(PostProcessEvent.BeforeUpscaling, context, "BeforeUpscaling", lastTarget); // Do temporal anti-aliasing first if (context.IsTemporalAntialiasingActive())