Browse Source

Got rid of the global callbacks thing and made callbacks a local field of the Fsr2ImageEffect script.

This way different applications of FSR2 within the same game can have different callbacks applied to them.
For example: a camera for rendering a 3D UI image to a render texture can have callbacks to apply mipmap bias only to the assets being drawn for the UI.
mac-autoexp
Nico de Poel 3 years ago
parent
commit
73fa30927b
  1. 7
      Assets/Scripts/Core/Fsr2.cs
  2. 8
      Assets/Scripts/Fsr2ImageEffect.cs
  3. 10
      Assets/Scripts/Fsr2PostProcessEffect.cs

7
Assets/Scripts/Core/Fsr2.cs

@ -30,13 +30,10 @@ namespace FidelityFX
/// </summary>
public static class Fsr2
{
// Allow overriding of certain Unity resource management behaviors by the programmer
public static IFsr2Callbacks GlobalCallbacks { get; set; } = new Fsr2CallbacksBase();
/// <summary>
/// Creates a new FSR2 context with standard parameters that are appropriate for the current platform.
/// </summary>
public static Fsr2Context CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, InitializationFlags flags = 0)
public static Fsr2Context CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, IFsr2Callbacks callbacks, InitializationFlags flags = 0)
{
if (SystemInfo.usesReversedZBuffer)
flags |= InitializationFlags.EnableDepthInverted;
@ -54,7 +51,7 @@ namespace FidelityFX
Flags = flags,
DisplaySize = displaySize,
MaxRenderSize = maxRenderSize,
Callbacks = GlobalCallbacks,
Callbacks = callbacks,
};
var context = new Fsr2Context();

8
Assets/Scripts/Fsr2ImageEffect.cs

@ -34,6 +34,8 @@ namespace FidelityFX
[RequireComponent(typeof(Camera))]
public class Fsr2ImageEffect : MonoBehaviour
{
public IFsr2Callbacks Callbacks = new Fsr2CallbacksBase();
public Fsr2.QualityMode qualityMode = Fsr2.QualityMode.Quality;
public bool performSharpenPass = true;
@ -109,7 +111,7 @@ namespace FidelityFX
// Apply a mipmap bias so that textures retain their sharpness
float biasOffset = Fsr2.GetMipmapBiasOffset(_renderSize.x, _displaySize.x);
Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset);
Callbacks.ApplyMipmapBias(biasOffset);
if (!SystemInfo.supportsComputeShaders)
{
@ -126,7 +128,7 @@ namespace FidelityFX
if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage;
if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure;
_context = Fsr2.CreateContext(_displaySize, _renderSize, flags);
_context = Fsr2.CreateContext(_displaySize, _renderSize, Callbacks, flags);
_dispatchCommandBuffer = new CommandBuffer { name = "FSR2 Dispatch" };
@ -151,7 +153,7 @@ namespace FidelityFX
{
// Undo the current mipmap bias offset
float biasOffset = Fsr2.GetMipmapBiasOffset(_renderSize.x, _prevDisplaySize.x);
Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset);
Callbacks.ApplyMipmapBias(-biasOffset);
// Restore the camera's original state
_renderCamera.depthTextureMode = _originalDepthTextureMode;

10
Assets/Scripts/Fsr2PostProcessEffect.cs

@ -190,15 +190,11 @@ namespace FidelityFX
if (settings.enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage;
if (settings.enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
flags |= Fsr2.InitializationFlags.EnableDebugChecking;
#endif
_fsrContext = Fsr2.CreateContext(DisplaySize, RenderSize, flags);
_fsrContext = Fsr2.CreateContext(DisplaySize, RenderSize, null, flags);
// Apply a mipmap bias so that textures retain their sharpness
float biasOffset = Fsr2.GetMipmapBiasOffset(RenderSize.x, DisplaySize.x);
Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset);
//Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset);
}
private void DestroyFsrContext()
@ -210,7 +206,7 @@ namespace FidelityFX
// Undo the previous mipmap bias adjustment
float biasOffset = Fsr2.GetMipmapBiasOffset(RenderSize.x, _prevDisplaySize.x);
Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset);
//Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset);
}
}

Loading…
Cancel
Save