Custom Depth Value Outputs?

Hello! I was curious if anyone knew what the value ranges on depth buffers and custom depth buffers where? I assumed that it was a scalar value between 0 and 1 where 1 is far away and 0 is near. I also assumed that the value would default to 0 in the case of custom depth for all screen space where the object being rendered was not present. However, I recently came across a masking technique that would seem to indicate that the opposite is true, or at the very least that I am woefully ignorant of what values are being output. My own attempts to debug this have only been met with white screens and frustration. Can anyone lend me a hand?

1 Like

Just had the same issue, thought I’d share my findings.
After some trying it seems that the Custom Depth values are distances from the camera to the objects in world coordinates.
The value “defaults” to some very large number (roughly 100000000, I wonder why) wherever you have no objects with Render CustomDepth Pass enabled.

To visualise the world distance, I dismiss any values above 500:

And get this (only the black pieces have Custom Depth enabled, and so become white when close enough):

In the end, I just set the the constant in the Subtract node to 100000000 to get the effect I wanted - only objects with Render CustomDepth Pass enabled change the pixels. You can also remove the last Min node to retain world distances.

2 Likes

I too thought the default value if no custom depth would be 0, but it doesn’t seem to be the case. Would like to know what it actually is.