In this short tutorial, I’ll show you a method to retrieve the distance value of a point in the render. This can be useful for implementing Compositing effects based on precise values, for example, to create masks that are active only beyond a certain distance.
Video Transcript
Hello everyone! As you may know, the Depth Render Pass in Compositing allows you to obtain the distance of objects from the virtual camera in the form of a 32-bit grayscale image.

Some time ago, I published a tutorial where I talked about this data and how to use it with or without normalization to implement fog or other distance-based effects.
In this short tutorial, I’ll show you a method to retrieve the distance value of a point in the render. This can be useful for implementing Compositing effects based on precise values, for example, to create masks that are active only beyond a certain distance.


Here’s the key point: if you have an image loaded in an Image editor and right-click on a point in it, Blender will show you the RGBA values of that pixel in the bottom bar. The Alpha channel, in particular, can be very helpful for this purpose. This way, you’ll be able to see the original render and locate the points you're interested in, then click on them and read the distance value in the Alpha field. Let me show you how it works.

Before starting the render, I enable the Depth Pass in the View Layer tab in the Properties editor. In this tab, the Depth information is labeled as Z.

After starting the render, in a Compositor editor, I connect the Depth output from the Render Layers node to the Alpha input of the Viewer node.

I then open an Image Editor and, within this editor, open the Viewer image.

Now, by right-clicking on the image, I’ll get the distance values in the Alpha field, in Blender units, from the camera, for each point in the image. Right-clicking on a point in the World Background will return a value of 10 billion, which is extremely high and used to indicate the virtually infinite distance of the virtual universe.

This method works both with the Depth Pass as it is and when it’s normalized. The difference is that the non-normalized value represents the actual distance in Blender units between the objects and the virtual camera, while the normalized value goes from 0 to 1, where 0 is the point closest to the camera and 1 is the farthest. I discussed these aspects in the tutorial I mentioned at the beginning.

When the Depth Pass is not Normalized, clicking on one of the tombstones gives me a value around 3585. To create a mask that is white for all objects located between the virtual camera and that value, and black in all other cases, all I have to do is go back to the Compositor editor and add a Math Less Than node to the node setup, connecting the Depth output to the first Value input of the new node and setting the value to 3585 or so for the second input.


Alright, that’s it for this short tutorial! Unlike most of my video tutorials, the PDF version of this tutorial is not currently available for download. However, you’ll find a link in the description to the page containing the PDF versions of many of my other video tutorials. In any case, this is a great time to subscribe to the channel and turn on notifications! See you soon!