diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs index 1140b0c..eca9149 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs @@ -22,8 +22,7 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.Rendering.PostProcessing; +using UnityEngine.Experimental.Rendering; using FidelityFX; namespace UnityEngine.Rendering.PostProcessing @@ -64,9 +63,13 @@ namespace UnityEngine.Rendering.PostProcessing [Serializable] public class GenerateReactiveParameters { + [Tooltip("A value to scale the output")] [Range(0, 2)] public float scale = 0.5f; + [Tooltip("A threshold value to generate a binary reactive mask")] [Range(0, 1)] public float cutoffThreshold = 0.2f; + [Tooltip("A value to set for the binary reactive mask")] [Range(0, 1)] public float binaryValue = 0.9f; + [Tooltip("Flags to determine how to generate the reactive mask")] public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax; } @@ -133,7 +136,7 @@ namespace UnityEngine.Rendering.PostProcessing context.camera.rect = _originalRect; } - public void Render(PostProcessRenderContext context) + public void Render(PostProcessRenderContext context, RenderTargetIdentifier opaqueOnly) { var cmd = context.command; cmd.BeginSample("FSR2"); @@ -156,7 +159,11 @@ namespace UnityEngine.Rendering.PostProcessing if (autoGenerateReactiveMask) { - // TODO: auto-generate reactive mask + SetupAutoReactiveDescription(context, opaqueOnly); + + cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, _renderSize.x, _renderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); + _fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd); + _dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive; } cmd.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, context.sourceFormat, default, 1, true); @@ -264,6 +271,18 @@ namespace UnityEngine.Rendering.PostProcessing } } + private void SetupAutoReactiveDescription(PostProcessRenderContext context, RenderTargetIdentifier opaqueOnly) + { + _genReactiveDescription.ColorOpaqueOnly = opaqueOnly; + _genReactiveDescription.ColorPreUpscale = null; + _genReactiveDescription.OutReactive = null; + _genReactiveDescription.RenderSize = _renderSize; + _genReactiveDescription.Scale = generateReactiveParameters.scale; + _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; + _genReactiveDescription.BinaryValue = generateReactiveParameters.binaryValue; + _genReactiveDescription.Flags = generateReactiveParameters.flags; + } + private class Callbacks : Fsr2CallbacksBase { private readonly PostProcessResources _resources; 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 9eb8ad2..8fd3e20 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 @@ -214,6 +214,7 @@ namespace UnityEngine.Rendering.PostProcessing PostProcessRenderContext m_CurrentContext; LogHistogram m_LogHistogram; + RenderTexture m_opaqueOnly; RenderTexture m_upscaledOutput; bool m_SettingsUpdateNeeded = true; @@ -283,6 +284,12 @@ namespace UnityEngine.Rendering.PostProcessing [ImageEffectUsesCommandBuffer] void OnRenderImage(RenderTexture src, RenderTexture dst) { + if (m_opaqueOnly != null) + { + m_opaqueOnly.Release(); + m_opaqueOnly = null; + } + if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) { // Blit the upscaled image to the backbuffer @@ -634,10 +641,12 @@ namespace UnityEngine.Rendering.PostProcessing aoRenderer.Get().RenderAfterOpaque(context); } + bool fsrRequiresOpaque = context.IsSuperResolutionActive() && superResolution.autoGenerateReactiveMask; // TODO or auto-TCR + bool isFogActive = fog.IsEnabledAndSupported(context); bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); int opaqueOnlyEffects = 0; - // TODO: if FSR2 is active & using auto-reactive/TCR, add opaque-only copy step + opaqueOnlyEffects += fsrRequiresOpaque ? 1 : 0; opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0; opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; @@ -662,7 +671,12 @@ namespace UnityEngine.Rendering.PostProcessing UpdateSrcDstForOpaqueOnly(ref srcTarget, ref dstTarget, context, cameraTarget, opaqueOnlyEffects); } - // TODO: create opaque-only texture copy for FSR2 auto-reactive/TCR + if (fsrRequiresOpaque) + { + m_opaqueOnly = context.GetScreenSpaceTemporaryRT(); + cmd.BuiltinBlit(context.source, m_opaqueOnly); + opaqueOnlyEffects--; + } if (isScreenSpaceReflectionsActive) { @@ -1141,7 +1155,7 @@ namespace UnityEngine.Rendering.PostProcessing var finalDestination = context.destination; context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat); context.destination = fsrTarget; - superResolution.Render(context); + superResolution.Render(context, m_opaqueOnly); context.source = fsrTarget; context.destination = finalDestination;