Browse Source

Implemented mipmap bias offsetting

stable
Nico de Poel 3 years ago
parent
commit
911d98f5a1
  1. 22
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

22
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;
}
}

Loading…
Cancel
Save