Browse Source

Take control of the camera target texture and blit directly to it. This allows FSR2 upscaling to work on cameras that output to a target texture.

stable
Nico de Poel 3 years ago
parent
commit
c37b796404
  1. 26
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

26
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

@ -216,6 +216,7 @@ namespace UnityEngine.Rendering.PostProcessing
RenderTexture m_opaqueOnly; RenderTexture m_opaqueOnly;
RenderTexture m_upscaledOutput; RenderTexture m_upscaledOutput;
RenderTexture m_originalTargetTexture;
bool m_SettingsUpdateNeeded = true; bool m_SettingsUpdateNeeded = true;
bool m_IsRenderingInSceneView = false; bool m_IsRenderingInSceneView = false;
@ -296,7 +297,20 @@ namespace UnityEngine.Rendering.PostProcessing
superResolution.ResetCameraViewport(m_CurrentContext); superResolution.ResetCameraViewport(m_CurrentContext);
// Blit the upscaled image to the backbuffer // Blit the upscaled image to the backbuffer
Graphics.Blit(m_upscaledOutput, dst);
if (m_originalTargetTexture != null)
{
Graphics.Blit(m_upscaledOutput, m_originalTargetTexture);
RenderTexture.active = dst;
// Put the original target texture back at the end of the frame
m_Camera.targetTexture = m_originalTargetTexture;
m_originalTargetTexture = null;
}
else
{
Graphics.Blit(m_upscaledOutput, dst);
}
RenderTexture.ReleaseTemporary(m_upscaledOutput); RenderTexture.ReleaseTemporary(m_upscaledOutput);
m_upscaledOutput = null; m_upscaledOutput = null;
return; return;
@ -448,6 +462,16 @@ namespace UnityEngine.Rendering.PostProcessing
{ {
volumeTrigger = transform; volumeTrigger = transform;
} }
void LateUpdate()
{
// Temporarily take control of the camera's target texture, so that the upscaled output doesn't get clipped
if (m_Camera.targetTexture != null && m_CurrentContext.IsSuperResolutionActive())
{
m_originalTargetTexture = m_Camera.targetTexture;
m_Camera.targetTexture = null;
}
}
void OnPreCull() void OnPreCull()
{ {

Loading…
Cancel
Save