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 6d08112..e7ff440 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 @@ -187,7 +187,7 @@ namespace UnityEngine.Rendering.PostProcessing var scaledRenderSize = _genReactiveDescription.RenderSize; cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); _fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd); - _dispatchDescription.Reactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.UavAutoReactive); + _dispatchDescription.Reactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive); } _fsrContext.Dispatch(_dispatchDescription, cmd); @@ -263,21 +263,21 @@ namespace UnityEngine.Rendering.PostProcessing var camera = context.camera; // Set up the main FSR2 dispatch parameters - _dispatchDescription.Color = new Fsr2.RenderTargetView(context.source); - _dispatchDescription.Depth = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); - _dispatchDescription.MotionVectors = new Fsr2.RenderTargetView(BuiltinRenderTextureType.MotionVectors); - _dispatchDescription.Exposure = Fsr2.RenderTargetView.Empty; - _dispatchDescription.Reactive = Fsr2.RenderTargetView.Empty; - _dispatchDescription.TransparencyAndComposition = Fsr2.RenderTargetView.Empty; - - if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(exposure); - if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(context.autoExposureTexture); - if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.RenderTargetView(reactiveMask); - if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.RenderTargetView(transparencyAndCompositionMask); + _dispatchDescription.Color = new Fsr2.ResourceView(context.source); + _dispatchDescription.Depth = new Fsr2.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); + _dispatchDescription.MotionVectors = new Fsr2.ResourceView(BuiltinRenderTextureType.MotionVectors); + _dispatchDescription.Exposure = Fsr2.ResourceView.Unassigned; + _dispatchDescription.Reactive = Fsr2.ResourceView.Unassigned; + _dispatchDescription.TransparencyAndComposition = Fsr2.ResourceView.Unassigned; + + if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr2.ResourceView(exposure); + if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr2.ResourceView(context.autoExposureTexture); + if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.ResourceView(reactiveMask); + if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.ResourceView(transparencyAndCompositionMask); var scaledRenderSize = GetScaledRenderSize(context.camera); - _dispatchDescription.Output = new Fsr2.RenderTargetView(context.destination); + _dispatchDescription.Output = new Fsr2.ResourceView(context.destination); _dispatchDescription.PreExposure = preExposure; _dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.Sharpness = sharpness; @@ -296,7 +296,7 @@ namespace UnityEngine.Rendering.PostProcessing _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; if (autoGenerateTransparencyAndComposition) { - _dispatchDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly); + _dispatchDescription.ColorOpaqueOnly = new Fsr2.ResourceView(colorOpaqueOnly); _dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold; _dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale; _dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale; @@ -313,9 +313,9 @@ namespace UnityEngine.Rendering.PostProcessing private void SetupAutoReactiveDescription(PostProcessRenderContext context) { // Set up the parameters to auto-generate a reactive mask - _genReactiveDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly); - _genReactiveDescription.ColorPreUpscale = new Fsr2.RenderTargetView(context.source); - _genReactiveDescription.OutReactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.UavAutoReactive); + _genReactiveDescription.ColorOpaqueOnly = new Fsr2.ResourceView(colorOpaqueOnly); + _genReactiveDescription.ColorPreUpscale = new Fsr2.ResourceView(context.source); + _genReactiveDescription.OutReactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive); _genReactiveDescription.RenderSize = GetScaledRenderSize(context.camera); _genReactiveDescription.Scale = generateReactiveParameters.scale; _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs index 9866358..1ba8192 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs @@ -166,18 +166,28 @@ namespace FidelityFX /// /// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader. /// - public readonly struct RenderTargetView + public readonly struct ResourceView { - public static readonly RenderTargetView Empty = new RenderTargetView(default); + /// + /// This value is the equivalent of not setting any value at all; all struct fields will have their default values. + /// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader. + /// + public static readonly ResourceView Unassigned = new ResourceView(default); - public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) + /// + /// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture. + /// Binding this to a shader can be seen as setting the texture variable inside the shader to null. + /// + public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None); + + public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) { RenderTarget = renderTarget; SubElement = subElement; MipLevel = mipLevel; } - public bool IsEmpty => RenderTarget.Equals(default); + public bool IsValid => !RenderTarget.Equals(default); public readonly RenderTargetIdentifier RenderTarget; public readonly RenderTextureSubElement SubElement; @@ -189,13 +199,13 @@ namespace FidelityFX /// public class DispatchDescription { - public RenderTargetView Color; - public RenderTargetView Depth; - public RenderTargetView MotionVectors; - public RenderTargetView Exposure; // optional - public RenderTargetView Reactive; // optional - public RenderTargetView TransparencyAndComposition; // optional - public RenderTargetView Output; + public ResourceView Color; + public ResourceView Depth; + public ResourceView MotionVectors; + public ResourceView Exposure; // optional + public ResourceView Reactive; // optional + public ResourceView TransparencyAndComposition; // optional + public ResourceView Output; public Vector2 JitterOffset; public Vector2 MotionVectorScale; public Vector2Int RenderSize; @@ -212,7 +222,7 @@ namespace FidelityFX // EXPERIMENTAL reactive mask generation parameters public bool EnableAutoReactive; - public RenderTargetView ColorOpaqueOnly; + public ResourceView ColorOpaqueOnly; public float AutoTcThreshold = 0.05f; public float AutoTcScale = 1.0f; public float AutoReactiveScale = 5.0f; @@ -225,9 +235,9 @@ namespace FidelityFX /// public class GenerateReactiveDescription { - public RenderTargetView ColorOpaqueOnly; - public RenderTargetView ColorPreUpscale; - public RenderTargetView OutReactive; + public ResourceView ColorOpaqueOnly; + public ResourceView ColorPreUpscale; + public ResourceView OutReactive; public Vector2Int RenderSize; public float Scale = 0.5f; public float CutoffThreshold = 0.2f; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs index ec3b38f..bb6c5de 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs @@ -158,19 +158,19 @@ namespace FidelityFX // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) - dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.AutoExposure); - else if (dispatchParams.Exposure.IsEmpty) - dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.DefaultExposure); + dispatchParams.Exposure = new Fsr2.ResourceView(_resources.AutoExposure); + else if (!dispatchParams.Exposure.IsValid) + dispatchParams.Exposure = new Fsr2.ResourceView(_resources.DefaultExposure); if (dispatchParams.EnableAutoReactive) { // Create the auto-TCR resources only when we need them if (_resources.AutoReactive == null) _resources.CreateTcrAutogenResources(_contextDescription); - + if (resetAccumulation) { - RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsEmpty ? Fsr2ShaderIDs.SrvOpaqueOnly : dispatchParams.ColorOpaqueOnly.RenderTarget; + RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr2ShaderIDs.SrvOpaqueOnly; commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly); } } @@ -180,8 +180,8 @@ namespace FidelityFX _resources.DestroyTcrAutogenResources(); } - if (dispatchParams.Reactive.IsEmpty) dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.DefaultReactive); - if (dispatchParams.TransparencyAndComposition.IsEmpty) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive); + if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new Fsr2.ResourceView(_resources.DefaultReactive); + if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.DefaultReactive); Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -225,8 +225,8 @@ namespace FidelityFX if (dispatchParams.EnableAutoReactive) { GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); - dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.AutoReactive); - dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.AutoComposition); + dispatchParams.Reactive = new Fsr2.ResourceView(_resources.AutoReactive); + dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.AutoComposition); } // Compute luminance pyramid @@ -436,27 +436,27 @@ namespace FidelityFX private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams) { - if (dispatchParams.Color.IsEmpty) + if (!dispatchParams.Color.IsValid) { Debug.LogError("Color resource is null"); } - if (dispatchParams.Depth.IsEmpty) + if (!dispatchParams.Depth.IsValid) { Debug.LogError("Depth resource is null"); } - if (dispatchParams.MotionVectors.IsEmpty) + if (!dispatchParams.MotionVectors.IsValid) { Debug.LogError("MotionVectors resource is null"); } - if (dispatchParams.Output.IsEmpty) + if (!dispatchParams.Output.IsValid) { Debug.LogError("Output resource is null"); } - if (!dispatchParams.Exposure.IsEmpty && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) + if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) { Debug.LogWarning("Exposure resource provided, however auto exposure flag is present"); }