Browse Source

Progressed implementation of reactive mask generation pass.

Added temporary RT to contain the generated reactive mask, bind it to the FSR2 inputs, and made it available as a toggle on the script.
mac-autoexp
Nico de Poel 3 years ago
parent
commit
5ed7a5279b
  1. 1
      Assets/Scenes/SampleScene.unity
  2. 24
      Assets/Scripts/Fsr2.cs
  3. 4
      Assets/Scripts/Fsr2Context.cs
  4. 23
      Assets/Scripts/Fsr2Controller.cs
  5. 2
      Assets/Scripts/Fsr2Pipeline.cs

1
Assets/Scenes/SampleScene.unity

@ -320,6 +320,7 @@ MonoBehaviour:
performSharpenPass: 1
sharpness: 0.8
enableFP16: 0
generateReactiveMask: 0
--- !u!114 &963194230
MonoBehaviour:
m_ObjectHideFlags: 0

24
Assets/Scripts/Fsr2.cs

@ -139,6 +139,10 @@ namespace FidelityFX
public Fsr2Callbacks Callbacks;
}
/// <summary>
/// The input and output resources are all optional. If they are null, the Fsr2Context won't try to bind them to any shaders.
/// This allows for customized and more efficient resource management outside of Fsr2Context, tailored to the specific scenario.
/// </summary>
public class DispatchDescription
{
public RenderTargetIdentifier? Color;
@ -162,16 +166,28 @@ namespace FidelityFX
public float ViewSpaceToMetersFactor;
}
/// <summary>
/// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR2 demo project.
/// </summary>
public class GenerateReactiveDescription
{
public RenderTargetIdentifier? ColorOpaqueOnly;
public RenderTargetIdentifier? ColorPreUpscale;
public RenderTargetIdentifier? OutReactive;
public Vector2Int RenderSize;
public float Scale;
public float CutoffThreshold;
public float BinaryValue;
public uint Flags;
public float Scale = 1.0f;
public float CutoffThreshold = 0.2f;
public float BinaryValue = 0.9f;
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax;
}
[Flags]
public enum GenerateReactiveFlags
{
ApplyTonemap = 1 << 0,
ApplyInverseTonemap = 1 << 1,
ApplyThreshold = 1 << 2,
UseComponentsMax = 1 << 3,
}
[Serializable, StructLayout(LayoutKind.Sequential)]

4
Assets/Scripts/Fsr2Context.cs

@ -217,10 +217,10 @@ namespace FidelityFX
GenReactiveConsts.scale = dispatchParams.Scale;
GenReactiveConsts.threshold = dispatchParams.CutoffThreshold;
GenReactiveConsts.binaryValue = dispatchParams.BinaryValue;
GenReactiveConsts.flags = dispatchParams.Flags;
GenReactiveConsts.flags = (uint)dispatchParams.Flags;
_generateReactiveConstantsBuffer.SetData(_generateReactiveConstantsArray);
((Fsr2GenerateReactivePipeline)_generateReactivePipeline).ScheduleDispatch(_commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
((Fsr2GenerateReactivePipeline)_generateReactivePipeline).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
}
private void SetupConstants(Fsr2.DispatchDescription dispatchParams, bool resetAccumulation)

23
Assets/Scripts/Fsr2Controller.cs

@ -21,6 +21,8 @@ namespace FidelityFX
[SerializeField] private bool enableFP16 = false;
[SerializeField] private bool generateReactiveMask = false;
private Fsr2Context _context;
private Vector2Int _renderSize;
private Vector2Int _displaySize;
@ -135,12 +137,6 @@ namespace FidelityFX
_renderCamera.aspect = (Screen.width * _originalRect.width) / (Screen.height * _originalRect.height);
_renderCamera.rect = new Rect(0, 0, _originalRect.width * _renderSize.x / _displaySize.x, _originalRect.height * _renderSize.y / _displaySize.y);
_genReactiveDescription.RenderSize = _renderSize;
_genReactiveDescription.Scale = 1.0f;
_genReactiveDescription.CutoffThreshold = 0.2f;
_genReactiveDescription.BinaryValue = 0.9f;
_genReactiveDescription.Flags = 0; // ApplyTonemap, ApplyInverseTonemap, ApplyThreshold, UseComponentsMax
_dispatchDescription.Color = null;
_dispatchDescription.Depth = null;
_dispatchDescription.MotionVectors = null;
@ -182,8 +178,14 @@ namespace FidelityFX
_dispatchCommandBuffer.Clear();
// UpscaleReactive: width, height, VK_FORMAT_R8_UNORM
//Context.GenerateReactiveMask();
if (generateReactiveMask)
{
_genReactiveDescription.RenderSize = _renderSize;
_dispatchCommandBuffer.GetTemporaryRT(Fsr2Pipeline.UavAutoReactive, _renderSize.x, _renderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
_context.GenerateReactiveMask(_genReactiveDescription, _dispatchCommandBuffer);
_dispatchDescription.Reactive = Fsr2Pipeline.UavAutoReactive;
}
_dispatchDescription.InputResourceSize = new Vector2Int(src.width, src.height);
@ -210,6 +212,11 @@ namespace FidelityFX
_dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2Pipeline.UavUpscaledOutput);
}
if (generateReactiveMask)
{
_dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2Pipeline.UavAutoReactive);
}
Graphics.ExecuteCommandBuffer(_dispatchCommandBuffer);
// Shut up the Unity warning about not writing to the destination texture

2
Assets/Scripts/Fsr2Pipeline.cs

@ -411,7 +411,7 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.ColorPreUpscale.Value, 0, RenderTextureSubElement.Color);
if (dispatchParams.OutReactive.HasValue)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavAutoExposure, dispatchParams.OutReactive.Value);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavAutoReactive, dispatchParams.OutReactive.Value);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants>());

Loading…
Cancel
Save