From ce9a64cba5fca56544bd037f8969b0f18c18951b Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 18 Mar 2023 14:15:14 +0100 Subject: [PATCH] Figured out a way to support cameras with target textures, that avoids errors about depth buffer mismatch. --- Assets/Scripts/Fsr2ImageEffect.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Fsr2ImageEffect.cs b/Assets/Scripts/Fsr2ImageEffect.cs index 030acd7..2e7ea37 100644 --- a/Assets/Scripts/Fsr2ImageEffect.cs +++ b/Assets/Scripts/Fsr2ImageEffect.cs @@ -80,7 +80,9 @@ namespace FidelityFX // Set up the original camera to output all of the required FSR2 input resources at the desired resolution _renderCamera = GetComponent(); + _originalRenderTarget = _renderCamera.targetTexture; _originalDepthTextureMode = _renderCamera.depthTextureMode; + _renderCamera.targetTexture = null; // Clear the camera's target texture so we can fully control how the output gets written _renderCamera.depthTextureMode = _originalDepthTextureMode | DepthTextureMode.Depth | DepthTextureMode.MotionVectors; // Initialize FSR2 context @@ -134,6 +136,7 @@ namespace FidelityFX } _renderCamera.depthTextureMode = _originalDepthTextureMode; + _renderCamera.targetTexture = _originalRenderTarget; if (_context != null) { @@ -250,7 +253,7 @@ namespace FidelityFX _renderCamera.rect = _originalRect; _renderCamera.ResetProjectionMatrix(); - if (dest != null && _renderCamera.targetTexture == null) + if (dest != null && _originalRenderTarget == null) { Debug.LogError("FSR2 is not set to output directly to the backbuffer! Please ensure that FSR2 is the final pass in the image effects chain."); Graphics.Blit(src, dest); @@ -281,7 +284,7 @@ namespace FidelityFX _context.Dispatch(_dispatchDescription, _dispatchCommandBuffer); // Output the upscaled image to the backbuffer - _dispatchCommandBuffer.Blit(Fsr2ShaderIDs.UavUpscaledOutput, _renderCamera.targetTexture != null ? _renderCamera.targetTexture : dest); + _dispatchCommandBuffer.Blit(Fsr2ShaderIDs.UavUpscaledOutput, _originalRenderTarget != null ? _originalRenderTarget : dest); _dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput); if (autoGenerateReactiveMask)