Browse Source

Back to basics: allow FSR2 to only output directly to the backbuffer

mac-autoexp
Nico de Poel 3 years ago
parent
commit
8668e0b3f6
  1. 39
      Assets/Scripts/Fsr2Controller.cs

39
Assets/Scripts/Fsr2Controller.cs

@ -240,8 +240,19 @@ namespace FidelityFX
_renderCamera.rect = _originalRect; _renderCamera.rect = _originalRect;
_renderCamera.ResetProjectionMatrix(); _renderCamera.ResetProjectionMatrix();
if (dest != null)
{
Debug.LogError("FSR2 is not set to output directly to the backbuffer");
Graphics.Blit(src, dest);
enabled = false;
return;
}
_dispatchCommandBuffer.Clear(); _dispatchCommandBuffer.Clear();
// Update the input resource descriptions
_dispatchDescription.InputResourceSize = new Vector2Int(src.width, src.height);
if (!enableAutoExposure && exposure != null) if (!enableAutoExposure && exposure != null)
{ {
_dispatchDescription.Exposure = exposure; _dispatchDescription.Exposure = exposure;
@ -265,30 +276,14 @@ namespace FidelityFX
_dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask; _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask;
} }
_dispatchDescription.InputResourceSize = new Vector2Int(src.width, src.height);
if (dest != null)
{
Debug.Log($"src = {src.width}x{src.height}, dest = {dest.width}x{dest.height}");
// We have more image effects lined up after this, so FSR2 can output straight to the intermediate render texture
// TODO: we should probably use a shader to include depth & motion vectors into the output, making sure they match the expected output resolution
_dispatchCommandBuffer.SetGlobalTexture(Fsr2Pipeline.UavUpscaledOutput, dest);
}
else
{
// We are rendering to the backbuffer, so we need a temporary render texture for FSR2 to output to
_dispatchCommandBuffer.GetTemporaryRT(Fsr2Pipeline.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true);
}
// We are rendering to the backbuffer, so we need a temporary render texture for FSR2 to output to
_dispatchCommandBuffer.GetTemporaryRT(Fsr2Pipeline.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true);
_context.Dispatch(_dispatchDescription, _dispatchCommandBuffer); _context.Dispatch(_dispatchDescription, _dispatchCommandBuffer);
// Output upscaled image to screen
// TODO: if `dest` is null, we likely don't care about the depth & motion vectors anymore
if (dest == null)
{
_dispatchCommandBuffer.Blit(Fsr2Pipeline.UavUpscaledOutput, dest);
_dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2Pipeline.UavUpscaledOutput);
}
// Output the upscaled image to the backbuffer
_dispatchCommandBuffer.Blit(Fsr2Pipeline.UavUpscaledOutput, dest);
_dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2Pipeline.UavUpscaledOutput);
if (autoGenerateReactiveMask) if (autoGenerateReactiveMask)
{ {
@ -298,7 +293,7 @@ namespace FidelityFX
Graphics.ExecuteCommandBuffer(_dispatchCommandBuffer); Graphics.ExecuteCommandBuffer(_dispatchCommandBuffer);
// Shut up the Unity warning about not writing to the destination texture // Shut up the Unity warning about not writing to the destination texture
Graphics.SetRenderTarget(dest);
RenderTexture.active = dest;
} }
} }
} }
Loading…
Cancel
Save