Browse Source

Abuse display buffer to store upscaled image and blit it to the camera output destination in OnRenderImage. Bit of a hack but it works to support not outputting directly to the camera target.

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

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

@ -210,6 +210,7 @@ namespace UnityEngine.Rendering.PostProcessing
CommandBuffer m_LegacyCmdBufferBeforeLighting; CommandBuffer m_LegacyCmdBufferBeforeLighting;
CommandBuffer m_LegacyCmdBufferOpaque; CommandBuffer m_LegacyCmdBufferOpaque;
CommandBuffer m_LegacyCmdBuffer; CommandBuffer m_LegacyCmdBuffer;
CommandBuffer m_BlitCmdBuffer;
Camera m_Camera; Camera m_Camera;
PostProcessRenderContext m_CurrentContext; PostProcessRenderContext m_CurrentContext;
LogHistogram m_LogHistogram; LogHistogram m_LogHistogram;
@ -251,6 +252,7 @@ namespace UnityEngine.Rendering.PostProcessing
m_LegacyCmdBufferBeforeLighting = new CommandBuffer { name = "Deferred Ambient Occlusion" }; m_LegacyCmdBufferBeforeLighting = new CommandBuffer { name = "Deferred Ambient Occlusion" };
m_LegacyCmdBufferOpaque = new CommandBuffer { name = "Opaque Only Post-processing" }; m_LegacyCmdBufferOpaque = new CommandBuffer { name = "Opaque Only Post-processing" };
m_LegacyCmdBuffer = new CommandBuffer { name = "Post-processing" }; m_LegacyCmdBuffer = new CommandBuffer { name = "Post-processing" };
m_BlitCmdBuffer = new CommandBuffer { name = "Backbuffer blit" };
m_Camera = GetComponent<Camera>(); m_Camera = GetComponent<Camera>();
@ -281,6 +283,16 @@ namespace UnityEngine.Rendering.PostProcessing
[ImageEffectUsesCommandBuffer] [ImageEffectUsesCommandBuffer]
void OnRenderImage(RenderTexture src, RenderTexture dst) void OnRenderImage(RenderTexture src, RenderTexture dst)
{ {
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{
// Blit the upscaled image to the backbuffer
m_BlitCmdBuffer.Blit(m_CurrentContext.destination, dst);
Graphics.ExecuteCommandBuffer(m_BlitCmdBuffer);
RenderTexture.active = dst;
return;
}
if (finalBlitToCameraTarget && !m_CurrentContext.stereoActive && DynamicResolutionAllowsFinalBlitToCameraTarget()) if (finalBlitToCameraTarget && !m_CurrentContext.stereoActive && DynamicResolutionAllowsFinalBlitToCameraTarget())
RenderTexture.active = dst; // silence warning RenderTexture.active = dst; // silence warning
else else
@ -572,6 +584,7 @@ namespace UnityEngine.Rendering.PostProcessing
m_LegacyCmdBufferBeforeLighting.Clear(); m_LegacyCmdBufferBeforeLighting.Clear();
m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBufferOpaque.Clear();
m_LegacyCmdBuffer.Clear(); m_LegacyCmdBuffer.Clear();
m_BlitCmdBuffer.Clear();
SetupContext(context); SetupContext(context);
@ -627,7 +640,7 @@ namespace UnityEngine.Rendering.PostProcessing
bool isFogActive = fog.IsEnabledAndSupported(context); bool isFogActive = fog.IsEnabledAndSupported(context);
bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context);
int opaqueOnlyEffects = 0; int opaqueOnlyEffects = 0;
// TODO: if FSR2 is active, add opaque-only copy step
// TODO: if FSR2 is active & using auto-reactive/TCR, add opaque-only copy step
opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0; opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0;
opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += isFogActive ? 1 : 0;
opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0;
@ -701,6 +714,13 @@ namespace UnityEngine.Rendering.PostProcessing
context.destination = cameraTarget; context.destination = cameraTarget;
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{
// Use the main display buffer for temporarily storing the upscaled full-resolution image
context.flip = true;
context.destination = Display.main.colorBuffer;
}
#if UNITY_2019_1_OR_NEWER #if UNITY_2019_1_OR_NEWER
if (finalBlitToCameraTarget && !m_CurrentContext.stereoActive && !RuntimeUtilities.scriptableRenderPipelineActive && DynamicResolutionAllowsFinalBlitToCameraTarget()) if (finalBlitToCameraTarget && !m_CurrentContext.stereoActive && !RuntimeUtilities.scriptableRenderPipelineActive && DynamicResolutionAllowsFinalBlitToCameraTarget())
{ {

Loading…
Cancel
Save