@@ -52,6 +52,24 @@ internal ProfilingSampler profilingSampler
52
52
/// </summary>
53
53
public TargetBuffer targetDepthBuffer ;
54
54
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
+
55
73
/// <summary>
56
74
/// What clear to apply when the color and depth buffer are bound
57
75
/// </summary>
@@ -270,7 +288,7 @@ internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera, Cullin
270
288
customPass . isExecuting = false ;
271
289
272
290
// Set back the camera color buffer if we were using a custom buffer as target
273
- if ( customPass . targetDepthBuffer != TargetBuffer . Camera )
291
+ if ( customPass . getConstrainedDepthBuffer ( ) != TargetBuffer . Camera )
274
292
CoreUtils . SetRenderTarget ( ctx . cmd , outputColorBuffer ) ;
275
293
} ) ;
276
294
}
@@ -307,16 +325,17 @@ bool IsMSAAEnabled(HDCamera hdCamera)
307
325
// This function must be only called from the ExecuteInternal method (requires current render target and current RT manager)
308
326
void SetCustomPassTarget ( CommandBuffer cmd )
309
327
{
328
+ TargetBuffer depth = getConstrainedDepthBuffer ( ) ;
310
329
// In case all the buffer are set to none, we can't bind anything
311
- if ( targetColorBuffer == TargetBuffer . None && targetDepthBuffer == TargetBuffer . None )
330
+ if ( targetColorBuffer == TargetBuffer . None && depth == TargetBuffer . None )
312
331
return ;
313
332
314
333
RTHandle colorBuffer = ( targetColorBuffer == TargetBuffer . Custom ) ? currentRenderTarget . customColorBuffer . Value : currentRenderTarget . colorBufferRG ;
315
- RTHandle depthBuffer = ( targetDepthBuffer == TargetBuffer . Custom ) ? currentRenderTarget . customDepthBuffer . Value : currentRenderTarget . depthBufferRG ;
334
+ RTHandle depthBuffer = ( depth == TargetBuffer . Custom ) ? currentRenderTarget . customDepthBuffer . Value : currentRenderTarget . depthBufferRG ;
316
335
317
- if ( targetColorBuffer == TargetBuffer . None && targetDepthBuffer != TargetBuffer . None )
336
+ if ( targetColorBuffer == TargetBuffer . None && depth != TargetBuffer . None )
318
337
CoreUtils . SetRenderTarget ( cmd , depthBuffer , clearFlags ) ;
319
- else if ( targetColorBuffer != TargetBuffer . None && targetDepthBuffer == TargetBuffer . None )
338
+ else if ( targetColorBuffer != TargetBuffer . None && depth == TargetBuffer . None )
320
339
CoreUtils . SetRenderTarget ( cmd , colorBuffer , clearFlags ) ;
321
340
else
322
341
{
0 commit comments