Browse Source

Further refinement to clarity and comments of the BiRP integration

mac-autoexp
Nico de Poel 3 years ago
parent
commit
65280ebf7a
  1. 19
      Assets/Scripts/Fsr2ImageEffect.cs

19
Assets/Scripts/Fsr2ImageEffect.cs

@ -105,13 +105,13 @@ namespace FidelityFX
private Fsr2Context _context; private Fsr2Context _context;
private Vector2Int _renderSize; private Vector2Int _renderSize;
private Vector2Int _displaySize; private Vector2Int _displaySize;
private bool _reset;
private float _appliedBiasOffset;
private bool _resetHistory;
private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription(); private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription();
private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription(); private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription();
private Fsr2ImageEffectHelper _helper; private Fsr2ImageEffectHelper _helper;
private float _appliedBiasOffset;
private Camera _renderCamera; private Camera _renderCamera;
private RenderTexture _originalRenderTarget; private RenderTexture _originalRenderTarget;
@ -257,6 +257,7 @@ namespace FidelityFX
private void Update() private void Update()
{ {
// Monitor for any changes in parameters that require a reset of the FSR2 context
var displaySize = GetDisplaySize(); var displaySize = GetDisplaySize();
if (displaySize.x != _prevDisplaySize.x || displaySize.y != _prevDisplaySize.y || qualityMode != _prevQualityMode || enableAutoExposure != _prevAutoExposure) 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() private void LateUpdate()
@ -307,7 +309,7 @@ namespace FidelityFX
private void SetupDispatchDescription() private void SetupDispatchDescription()
{ {
// Set up the main FSR2 dispatch parameters // 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.Color = null;
_dispatchDescription.Depth = null; _dispatchDescription.Depth = null;
_dispatchDescription.MotionVectors = null; _dispatchDescription.MotionVectors = null;
@ -331,8 +333,8 @@ namespace FidelityFX
_dispatchDescription.CameraFar = _renderCamera.farClipPlane; _dispatchDescription.CameraFar = _renderCamera.farClipPlane;
_dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad;
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity _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 // Set up the parameters for the optional experimental auto-TCR feature
_dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition;
@ -398,12 +400,13 @@ namespace FidelityFX
if (autoGenerateReactiveMask) 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); _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, _renderSize.x, _renderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
_context.GenerateReactiveMask(_genReactiveDescription, _dispatchCommandBuffer); _context.GenerateReactiveMask(_genReactiveDescription, _dispatchCommandBuffer);
_dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive; _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); _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GetDefaultFormat(), default, 1, true);
_context.Dispatch(_dispatchDescription, _dispatchCommandBuffer); _context.Dispatch(_dispatchDescription, _dispatchCommandBuffer);

Loading…
Cancel
Save