From 65280ebf7a4d4a79daf45511a44506f3e60ffc19 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 3 Jun 2023 18:52:12 +0200 Subject: [PATCH] Further refinement to clarity and comments of the BiRP integration --- Assets/Scripts/Fsr2ImageEffect.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Fsr2ImageEffect.cs b/Assets/Scripts/Fsr2ImageEffect.cs index fff3418..5be9810 100644 --- a/Assets/Scripts/Fsr2ImageEffect.cs +++ b/Assets/Scripts/Fsr2ImageEffect.cs @@ -105,13 +105,13 @@ namespace FidelityFX private Fsr2Context _context; private Vector2Int _renderSize; private Vector2Int _displaySize; - private bool _reset; + private float _appliedBiasOffset; + private bool _resetHistory; private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription(); private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription(); private Fsr2ImageEffectHelper _helper; - private float _appliedBiasOffset; private Camera _renderCamera; private RenderTexture _originalRenderTarget; @@ -257,6 +257,7 @@ namespace FidelityFX private void Update() { + // Monitor for any changes in parameters that require a reset of the FSR2 context var displaySize = GetDisplaySize(); if (displaySize.x != _prevDisplaySize.x || displaySize.y != _prevDisplaySize.y || qualityMode != _prevQualityMode || enableAutoExposure != _prevAutoExposure) { @@ -266,9 +267,10 @@ namespace FidelityFX } } - public void Reset() + public void ResetHistory() { - _reset = true; + // Reset the temporal accumulation, for when the camera cuts to a different location or angle + _resetHistory = true; } private void LateUpdate() @@ -307,7 +309,7 @@ namespace FidelityFX private void SetupDispatchDescription() { // Set up the main FSR2 dispatch parameters - // The input and output textures are left blank here, as they are already being bound elsewhere in this source file + // The input and output textures are left blank here, as they get bound directly through SetGlobalTexture and GetTemporaryRT elsewhere in this source file _dispatchDescription.Color = null; _dispatchDescription.Depth = null; _dispatchDescription.MotionVectors = null; @@ -331,8 +333,8 @@ namespace FidelityFX _dispatchDescription.CameraFar = _renderCamera.farClipPlane; _dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity - _dispatchDescription.Reset = _reset; - _reset = false; + _dispatchDescription.Reset = _resetHistory; + _resetHistory = false; // Set up the parameters for the optional experimental auto-TCR feature _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; @@ -398,12 +400,13 @@ namespace FidelityFX if (autoGenerateReactiveMask) { + // The auto-reactive mask pass is executed separately from the main FSR2 passes _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, _renderSize.x, _renderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); _context.GenerateReactiveMask(_genReactiveDescription, _dispatchCommandBuffer); _dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive; } - // We are rendering to the backbuffer, so we need a temporary render texture for FSR2 to output to + // The backbuffer is not set up to allow random-write access, so we need a temporary render texture for FSR2 to output to _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GetDefaultFormat(), default, 1, true); _context.Dispatch(_dispatchDescription, _dispatchCommandBuffer);