From 8668e0b3f625f848ef203de622ca522c34eaf99a Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 6 Mar 2023 15:13:00 +0100 Subject: [PATCH] Back to basics: allow FSR2 to only output directly to the backbuffer --- Assets/Scripts/Fsr2Controller.cs | 39 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index fe047a2..3ffb640 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -240,7 +240,18 @@ namespace FidelityFX _renderCamera.rect = _originalRect; _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(); + + // Update the input resource descriptions + _dispatchDescription.InputResourceSize = new Vector2Int(src.width, src.height); if (!enableAutoExposure && exposure != null) { @@ -265,30 +276,14 @@ namespace FidelityFX _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); - // 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) { @@ -298,7 +293,7 @@ namespace FidelityFX Graphics.ExecuteCommandBuffer(_dispatchCommandBuffer); // Shut up the Unity warning about not writing to the destination texture - Graphics.SetRenderTarget(dest); + RenderTexture.active = dest; } } }