Browse Source

Added option to enable FP16 from the scene

mac-autoexp
Nico de Poel 3 years ago
parent
commit
d47b8c78da
  1. 3
      Assets/Scenes/SampleScene.unity
  2. 13
      Assets/Scripts/Fsr2Controller.cs

3
Assets/Scenes/SampleScene.unity

@ -317,6 +317,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
qualityMode: 3
performSharpenPass: 1
sharpness: 0.8
enableFP16: 0
--- !u!114 &963194230
MonoBehaviour:
m_ObjectHideFlags: 0

13
Assets/Scripts/Fsr2Controller.cs

@ -19,6 +19,8 @@ namespace FidelityFX
[SerializeField, Range(0, 1)] private float sharpness = 0.8f;
[SerializeField] private bool enableFP16 = false;
private Fsr2Context _context;
private Vector2Int _renderSize;
private Vector2Int _displaySize;
@ -41,10 +43,14 @@ namespace FidelityFX
private void OnEnable()
{
Fsr2.InitializationFlags flags = Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation;
if (enableFP16)
flags |= Fsr2.InitializationFlags.EnableFP16Usage;
_displaySize = new Vector2Int(Screen.width, Screen.height);
Fsr2.GetRenderResolutionFromQualityMode(out var renderWidth, out var renderHeight, _displaySize.x, _displaySize.y, qualityMode);
_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
_renderCamera = GetComponent<Camera>();
@ -53,7 +59,7 @@ namespace FidelityFX
_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 loop
_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
_opaqueOnlyCommandBuffer.SetGlobalTexture(Fsr2Pipeline.SrvOpaqueOnly, BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color);
@ -65,8 +71,7 @@ namespace FidelityFX
_inputsCommandBuffer.SetGlobalTexture(Fsr2Pipeline.SrvInputMotionVectors, BuiltinRenderTextureType.MotionVectors);
_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);
Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset);

Loading…
Cancel
Save