Browse Source

Implemented auto-exposure feature.

The way this works: compute luminance always outputs an auto-exposure value. The passes using exposure as input can either use this auto-exposure, or use the default read-only exposure value, or use an application-provided exposure.
mac-autoexp
Nico de Poel 3 years ago
parent
commit
3ffbc0573e
  1. 3
      Assets/Scenes/SampleScene.unity
  2. 17
      Assets/Scripts/Fsr2Context.cs
  3. 8
      Assets/Scripts/Fsr2Controller.cs

3
Assets/Scenes/SampleScene.unity

@ -316,9 +316,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 955cb66a9ecc20441a7e32934c9b4690, type: 3}
m_Name:
m_EditorClassIdentifier:
qualityMode: 3
qualityMode: 2
performSharpenPass: 1
sharpness: 0.8
enableAutoExposure: 1
enableFP16: 0
reactiveMask: {fileID: 0}
transparencyAndCompositionMask: {fileID: 0}

17
Assets/Scripts/Fsr2Context.cs

@ -130,8 +130,12 @@ namespace FidelityFX
bool resetAccumulation = dispatchParams.Reset || _firstExecution;
_firstExecution = false;
// TODO: auto-exposure flag
if (dispatchParams.Exposure == null) dispatchParams.Exposure = _resources.DefaultExposure;
// if auto exposure is enabled use the auto exposure SRV, otherwise what the app sends.
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
dispatchParams.Exposure = _resources.AutoExposure;
else if (dispatchParams.Exposure == null)
dispatchParams.Exposure = _resources.DefaultExposure;
if (dispatchParams.Reactive == null) dispatchParams.Reactive = _resources.DefaultReactive;
if (dispatchParams.TransparencyAndComposition == null) dispatchParams.TransparencyAndComposition = _resources.DefaultReactive;
Fsr2Pipeline.RegisterResources(commandBuffer, _contextDescription, dispatchParams);
@ -347,8 +351,7 @@ namespace FidelityFX
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y;
}
private static void SpdSetup(RectInt rectInfo,
out Vector2Int dispatchThreadGroupCount, out Vector2Int workGroupOffset, out Vector2Int numWorkGroupsAndMips, int mips = -1)
private static void SpdSetup(RectInt rectInfo, out Vector2Int dispatchThreadGroupCount, out Vector2Int workGroupOffset, out Vector2Int numWorkGroupsAndMips, int mips = -1)
{
workGroupOffset = new Vector2Int(rectInfo.x / 64, rectInfo.y / 64);
@ -367,7 +370,7 @@ namespace FidelityFX
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams)
{
// Global texture binding may happen as part of the command list, which is why we check these after running the process at least once
// Global texture binding may be queued as part of the command list, which is why we check these after running the process at least once
if (!_firstExecution)
{
if (!dispatchParams.Color.HasValue && Shader.GetGlobalTexture(Fsr2Pipeline.SrvInputColor) == null)
@ -443,7 +446,7 @@ namespace FidelityFX
if (infiniteDepth)
{
if (dispatchParams.CameraNear != float.MaxValue)
if (dispatchParams.CameraNear < float.MaxValue)
{
Debug.LogWarning("EnableDepthInfinite and EnableDepthInverted present, yet CameraNear != float.MaxValue");
}
@ -463,7 +466,7 @@ namespace FidelityFX
if (infiniteDepth)
{
if (dispatchParams.CameraFar != float.MaxValue)
if (dispatchParams.CameraFar < float.MaxValue)
{
Debug.LogWarning("EnableDepthInfinite present, yet CameraFar != float.MaxValue");
}

8
Assets/Scripts/Fsr2Controller.cs

@ -17,6 +17,8 @@ namespace FidelityFX
public bool performSharpenPass = true;
[Range(0, 1)] public float sharpness = 0.8f;
public bool enableAutoExposure = false;
[Tooltip("Allow the use of half precision compute operations, potentially improving performance")]
public bool enableFP16 = false;
@ -67,9 +69,9 @@ namespace FidelityFX
// Initialize FSR2 context
Fsr2.InitializationFlags flags = 0;
if (enableFP16)
flags |= Fsr2.InitializationFlags.EnableFP16Usage;
if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure;
if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
flags |= Fsr2.InitializationFlags.EnableDebugChecking;
#endif

Loading…
Cancel
Save