@ -19,6 +19,8 @@ namespace FidelityFX
[SerializeField, Range(0, 1)] private float sharpness = 0.8f ;
[SerializeField, Range(0, 1)] private float sharpness = 0.8f ;
[SerializeField] private bool enableFP16 = false ;
private Fsr2Context _context ;
private Fsr2Context _context ;
private Vector2Int _renderSize ;
private Vector2Int _renderSize ;
private Vector2Int _displaySize ;
private Vector2Int _displaySize ;
@ -41,10 +43,14 @@ namespace FidelityFX
private void OnEnable ( )
private void OnEnable ( )
{
{
Fsr2 . InitializationFlags flags = Fsr2 . InitializationFlags . EnableMotionVectorsJitterCancellation ;
if ( enableFP16 )
flags | = Fsr2 . InitializationFlags . EnableFP16Usage ;
_displaySize = new Vector2Int ( Screen . width , Screen . height ) ;
_displaySize = new Vector2Int ( Screen . width , Screen . height ) ;
Fsr2 . GetRenderResolutionFromQualityMode ( out var renderWidth , out var renderHeight , _displaySize . x , _displaySize . y , qualityMode ) ;
Fsr2 . GetRenderResolutionFromQualityMode ( out var renderWidth , out var renderHeight , _displaySize . x , _displaySize . y , qualityMode ) ;
_renderSize = new Vector2Int ( renderWidth , renderHeight ) ;
_renderSize = new Vector2Int ( renderWidth , renderHeight ) ;
_context = Fsr2 . CreateContext ( _displaySize , _renderSize , Fsr2 . InitializationFlags . EnableMotionVectorsJitterCancellation ) ;
_context = Fsr2 . CreateContext ( _displaySize , _renderSize , flags ) ;
// Set up the original camera to output all of the required FSR2 input resources at the desired resolution
// Set up the original camera to output all of the required FSR2 input resources at the desired resolution
_renderCamera = GetComponent < Camera > ( ) ;
_renderCamera = GetComponent < Camera > ( ) ;
@ -53,7 +59,7 @@ namespace FidelityFX
_dispatchCommandBuffer = new CommandBuffer { name = "FSR2 Dispatch" } ;
_dispatchCommandBuffer = new CommandBuffer { name = "FSR2 Dispatch" } ;
// Create command buffers to bind the camera's output at the right moments in the rendering pipeline
// Create command buffers to bind the camera's output at the right moments in the render loo p
_opaqueOnlyCommandBuffer = new CommandBuffer { name = "FSR2 Opaque Input" } ;
_opaqueOnlyCommandBuffer = new CommandBuffer { name = "FSR2 Opaque Input" } ;
// TODO: may need to copy the opaque-only render buffer to a temp RT here, in which case we'll need an additional CommandBuffer to release the temp RT again
// TODO: may need to copy the opaque-only render buffer to a temp RT here, in which case we'll need an additional CommandBuffer to release the temp RT again
_opaqueOnlyCommandBuffer . SetGlobalTexture ( Fsr2Pipeline . SrvOpaqueOnly , BuiltinRenderTextureType . CameraTarget , RenderTextureSubElement . Color ) ;
_opaqueOnlyCommandBuffer . SetGlobalTexture ( Fsr2Pipeline . SrvOpaqueOnly , BuiltinRenderTextureType . CameraTarget , RenderTextureSubElement . Color ) ;
@ -65,8 +71,7 @@ namespace FidelityFX
_inputsCommandBuffer . SetGlobalTexture ( Fsr2Pipeline . SrvInputMotionVectors , BuiltinRenderTextureType . MotionVectors ) ;
_inputsCommandBuffer . SetGlobalTexture ( Fsr2Pipeline . SrvInputMotionVectors , BuiltinRenderTextureType . MotionVectors ) ;
_renderCamera . AddCommandBuffer ( CameraEvent . BeforeImageEffects , _inputsCommandBuffer ) ;
_renderCamera . AddCommandBuffer ( CameraEvent . BeforeImageEffects , _inputsCommandBuffer ) ;
// Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0;
// May need to leave this to the game dev, as we don't know which textures do and don't belong to the 3D scene
// Apply a mipmap bias so that textures retain their original sharpness
float biasOffset = Fsr2 . GetMipmapBiasOffset ( _renderSize . x , _displaySize . x ) ;
float biasOffset = Fsr2 . GetMipmapBiasOffset ( _renderSize . x , _displaySize . x ) ;
Fsr2 . GlobalCallbacks . ApplyMipmapBias ( biasOffset ) ;
Fsr2 . GlobalCallbacks . ApplyMipmapBias ( biasOffset ) ;