Understanding the `Scene Depth` node of post-processing shaders

I am struggling to make sense of the UVs input of the Scene Depth post-processing shader node.

When I leave the UVs input unconnected, the output seems to be weirdly scaled down into the top-left corner of the screen:


My understanding is that when the UVs input is left unconnected, the depth is sampled at the values I have manually typed in, so in this case X: 0.0 and Y: 0.0
NodeUVsDefaults

If that was the case, the output image would be one solid color, for the depth at UV coord 0,0. In reality, the constant values I type into those fields don’t have any influence on the output. I tried (0,0), (0.5,0.5) and (1000,1000), all gave the same results as in the screenshot above.

When I connect the UVs input to the ViewportUV output from the ScreenPosition node, the output renders as I expected:


Can someone explain to me what the ScreenDepth node actually does when the UVs input is left unconnected? It honestly smells a bit buggy to me, but as important and frequently used as the node is, I can’t really imagine it being bugged.

It’s not used for anything as far as I’m aware when the UVs are set to the default “coordinates” mode. The reason your image is bunched to the top right is due to resolution scaling. Set your resolution scale to 100% and it would fix that - or as you have done here, use the viewport Us instead.
The situation when the X & Y value are used is when the node is set to the “offset fraction” mode, where inputs define an amount of offset instead of an absolute position.

2 Likes

Thanks, my reslution scale (Settings → Engine Scalability Settings → Resolution Scale) is at 100%. The part that confuses me is that only the Scene Depth node seems to show this behaviour. Here’s a very quick test where I blend the Scene Depth output with some Texture Sample output. Notably, the UVs input of both nodes is unconnected, still the Texture Sample fills the whole screen, while the Scene Depth is bunched to the top-left again.


Click on the viewport settings in the top left of the editor. Default screen scale is around 60%. This is different than the engine scalability settings.

Thanks, I think I understand now. I also found Screen Percentage with Temporal Upscale in Unreal Engine | Unreal Engine 5.1 Documentation, which gives a little bit of information on UVs when supersampling is used. The Scene Depth node seems to use pre-supersampling UVs when the UVs input is unconnected, regardless of whether the shader is run before or after the supersampling step. I still think this is weird behaviour - I don’t know why anyone would want to work on pre-supersampling UVs in a post-supersampling shader, but at least I understand now and am wary to always use ScreenPosition’s ViewportUVs :smiley:

Indeed, not sure why it work that way by default so it may be a bug.

1 Like