Skip to content

Commit 093c8a4

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [2022.3] Fix DRS + CustomPass AfterPostprocess and camera depth
1 parent c62afec commit 093c8a4

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/CustomPassDrawer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ void DoCommonSettingsGUI(ref Rect rect)
172172
{
173173
EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
174174
rect.y += Styles.defaultLineSpace;
175+
176+
CustomPass.TargetBuffer requestedDepth = m_TargetDepthBuffer.GetEnumValue<CustomPass.TargetBuffer>();
177+
if (m_CustomPass.getConstrainedDepthBuffer() != requestedDepth)
178+
{
179+
Rect helpBoxRect = rect;
180+
float helpBoxHeight = EditorGUIUtility.singleLineHeight * 2;
181+
helpBoxRect.height = helpBoxHeight;
182+
EditorGUI.HelpBox(helpBoxRect, "Camera depth isn't supported when dynamic scaling is on. We will automatically fall back to not doing depth-testing for this pass.", MessageType.Warning);
183+
rect.y += helpBoxHeight;
184+
}
175185
}
176186

177187
if ((commonPassUIFlags & PassUIFlag.ClearFlags) != 0)
@@ -264,6 +274,13 @@ internal float GetPropertyHeight(SerializedProperty property, GUIContent label)
264274
}
265275

266276
height += Styles.defaultLineSpace * lines;
277+
278+
// Add height for the help box if it will be shown
279+
if ((commonPassUIFlags & PassUIFlag.TargetDepthBuffer) != 0 &&
280+
m_CustomPass.getConstrainedDepthBuffer() != m_TargetDepthBuffer.GetEnumValue<CustomPass.TargetBuffer>())
281+
{
282+
height += EditorGUIUtility.singleLineHeight * 2; // Help box height
283+
}
267284
}
268285

269286
return height + GetPassHeight(property);

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ internal ProfilingSampler profilingSampler
5252
/// </summary>
5353
public TargetBuffer targetDepthBuffer;
5454

55+
// The actual depth buffer has to follow some constraints, and thus may not be the same result as the target
56+
// depth buffer that the user has requested. Apply these constraints and return a result.
57+
internal TargetBuffer getConstrainedDepthBuffer()
58+
{
59+
TargetBuffer depth = targetDepthBuffer;
60+
if (depth == TargetBuffer.Camera &&
61+
HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.enabled &&
62+
currentHDCamera.allowDynamicResolution &&
63+
injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
64+
{
65+
// This custom pass is injected after postprocessing, and Dynamic Resolution Scaling is enabled, which
66+
// means an upscaler is active. In this case, the camera color buffer is the full display resolution,
67+
// but the camera depth buffer is a lower, pre-upscale resolution. So we cannot do depth testing here.
68+
depth = TargetBuffer.None;
69+
}
70+
return depth;
71+
}
72+
5573
/// <summary>
5674
/// What clear to apply when the color and depth buffer are bound
5775
/// </summary>
@@ -272,7 +290,7 @@ virtual internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera
272290
customPass.isExecuting = false;
273291

274292
// Set back the camera color buffer if we were using a custom buffer as target
275-
if (customPass.targetDepthBuffer != TargetBuffer.Camera)
293+
if (customPass.getConstrainedDepthBuffer() != TargetBuffer.Camera)
276294
CoreUtils.SetRenderTarget(ctx.cmd, outputColorBuffer);
277295
});
278296
}
@@ -309,16 +327,17 @@ bool IsMSAAEnabled(HDCamera hdCamera)
309327
// This function must be only called from the ExecuteInternal method (requires current render target and current RT manager)
310328
void SetCustomPassTarget(CommandBuffer cmd)
311329
{
330+
TargetBuffer depth = getConstrainedDepthBuffer();
312331
// In case all the buffer are set to none, we can't bind anything
313-
if (targetColorBuffer == TargetBuffer.None && targetDepthBuffer == TargetBuffer.None)
332+
if (targetColorBuffer == TargetBuffer.None && depth == TargetBuffer.None)
314333
return;
315334

316335
RTHandle colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? currentRenderTarget.customColorBuffer.Value : currentRenderTarget.colorBufferRG;
317-
RTHandle depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG;
336+
RTHandle depthBuffer = (depth == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG;
318337

319-
if (targetColorBuffer == TargetBuffer.None && targetDepthBuffer != TargetBuffer.None)
338+
if (targetColorBuffer == TargetBuffer.None && depth != TargetBuffer.None)
320339
CoreUtils.SetRenderTarget(cmd, depthBuffer, clearFlags);
321-
else if (targetColorBuffer != TargetBuffer.None && targetDepthBuffer == TargetBuffer.None)
340+
else if (targetColorBuffer != TargetBuffer.None && depth == TargetBuffer.None)
322341
CoreUtils.SetRenderTarget(cmd, colorBuffer, clearFlags);
323342
else
324343
{

0 commit comments

Comments
 (0)