Skip to content

Commit 2117d85

Browse files
UnityAljoshaEvergreen
authored andcommitted
SwitchActiveTexturesToBackbuffer for URP
1 parent 87b96ed commit 2117d85

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/FrameData/UniversalResourceData.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ public TextureHandle activeColorTexture
3636
}
3737
}
3838

39+
/// <summary>
40+
/// Switch the active color and depth texture to the backbuffer. Once switched, isActiveTargetBackBuffer will return true.
41+
/// The activeColorTexture and activeDepthTexture will then return the backbuffer. This should be called after a render pass
42+
/// that blits/copies the cameraColor to the backbuffer is recorded in the render graph. The following passes will then
43+
/// automatically use the backbuffer as active color and depth. URP will not add the final blit pass if this method is called before
44+
/// that render pass.
45+
/// </summary>
46+
public void SwitchActiveTexturesToBackbuffer()
47+
{
48+
activeColorID = UniversalResourceData.ActiveID.BackBuffer;
49+
activeDepthID = UniversalResourceData.ActiveID.BackBuffer;
50+
}
51+
3952
/// <summary>
4053
/// The active depth target ID.
4154
/// </summary>

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRendererRenderGraph.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,8 +1430,7 @@ private void OnAfterRendering(RenderGraph renderGraph, bool applyPostProcessing)
14301430

14311431
if (isTargetBackbuffer)
14321432
{
1433-
resourceData.activeColorID = UniversalResourceData.ActiveID.BackBuffer;
1434-
resourceData.activeDepthID = UniversalResourceData.ActiveID.BackBuffer;
1433+
resourceData.SwitchActiveTexturesToBackbuffer();
14351434
}
14361435
}
14371436

@@ -1460,8 +1459,7 @@ private void OnAfterRendering(RenderGraph renderGraph, bool applyPostProcessing)
14601459
var source = resourceData.cameraColor;
14611460
m_PostProcessPassRenderGraph.RenderFinalPassRenderGraph(renderGraph, frameData, in source, in overlayUITexture, in target, needsColorEncoding);
14621461

1463-
resourceData.activeColorID = UniversalResourceData.ActiveID.BackBuffer;
1464-
resourceData.activeDepthID = UniversalResourceData.ActiveID.BackBuffer;
1462+
resourceData.SwitchActiveTexturesToBackbuffer();
14651463
}
14661464

14671465
bool cameraTargetResolved =
@@ -1488,8 +1486,7 @@ private void OnAfterRendering(RenderGraph renderGraph, bool applyPostProcessing)
14881486
debugHandler?.UpdateShaderGlobalPropertiesForFinalValidationPass(renderGraph, cameraData, !resolveToDebugScreen);
14891487

14901488
m_FinalBlitPass.Render(renderGraph, frameData, cameraData, source, target, overlayUITexture);
1491-
resourceData.activeColorID = UniversalResourceData.ActiveID.BackBuffer;
1492-
resourceData.activeDepthID = UniversalResourceData.ActiveID.BackBuffer;
1489+
resourceData.SwitchActiveTexturesToBackbuffer();
14931490
}
14941491

14951492
// TODO RENDERGRAPH: we need to discuss and decide if RenderPassEvent.AfterRendering injected passes should only be called after the last camera in the stack

0 commit comments

Comments
 (0)