From 911d98f5a16f49c735970ad38f11be700a85b470 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 30 May 2023 12:32:14 +0200 Subject: [PATCH] Implemented mipmap bias offsetting --- .../Runtime/Effects/SuperResolution.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs index 4caaa96..1140b0c 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs @@ -79,6 +79,9 @@ namespace UnityEngine.Rendering.PostProcessing private Vector2Int _displaySize; private bool _reset; + private IFsr2Callbacks _callbacks; + private float _appliedBiasOffset; + private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription(); private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription(); @@ -176,11 +179,16 @@ namespace UnityEngine.Rendering.PostProcessing if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage; if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure; - _fsrContext = Fsr2.CreateContext(_displaySize, _renderSize, CallbacksFactory(context), flags); + _callbacks = CallbacksFactory(context); + _fsrContext = Fsr2.CreateContext(_displaySize, _renderSize, _callbacks, flags); // Apply a mipmap bias so that textures retain their sharpness float biasOffset = Fsr2.GetMipmapBiasOffset(_renderSize.x, _displaySize.x); - //Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset); + if (!float.IsNaN(biasOffset)) + { + _callbacks.ApplyMipmapBias(biasOffset); + _appliedBiasOffset = biasOffset; + } } private void DestroyFsrContext() @@ -189,10 +197,12 @@ namespace UnityEngine.Rendering.PostProcessing { _fsrContext.Destroy(); _fsrContext = null; - - // Undo the previous mipmap bias adjustment - float biasOffset = Fsr2.GetMipmapBiasOffset(_renderSize.x, _prevDisplaySize.x); - //Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset); + } + + if (!float.IsNaN(_appliedBiasOffset) && _appliedBiasOffset != 0f) + { + _callbacks.ApplyMipmapBias(-_appliedBiasOffset); + _appliedBiasOffset = 0f; } }