I want to render depth maps and surface Normal maps of different 3D shapes using Cycles.

To be able to get depth maps, I attempted the two used methods that includes creating nodes here and played around with the parameters to get depth maps.

However, I run into the same problem that the question asker has run into (getting almost completely white images): I know accurate depth maps must only be stored in OpenEXR files but I also need to be able to view the depth maps for visualization purposes.

I am pretty new to the concepts of node trees in Blender and would appreciate if someone can give me some step-by-step instructions on how I can create node trees that store the depth maps (with a black background) on disk in OpenEXR or .txt files and map the values to 0-255 so that I can have some visualization, although less accurate.

Another thing: how can I avoid getting truncated depth maps?

Here is the best results I could get through trial and error:

enter image description here

And here is a .blend file which includes the 3D mesh I am trying to render depth maps for, in case you need.


To visualize the Z depth just use the Normalize node. Normalize will take the lowest and highest values of the image and scale them to be 0 (black) and 1 (white) respectively. All values in between will be scaled linearly as well. And maybe also enable transparency...

enter image description here


This is a question about compromises. As you admitted, a low bit depth will result in far less information being conveyed in the output. This can be okay, depending on how you use it.

Here's a simple solution: Using the Mist pass.

This has its own quirks. The Mist pass is essentially a normalized depth pass, using the furthest away rendered geometry. It's also anti-aliased, which can be good or bad depending on how you want to use it.

The mist pass carries the same level of detail across all your geometry. You can find it directly under the Z pass (You can see it in your screenshot).

Another solution with different quirks is to convert your depth map into a disparity map.

A depth map stores distance in units, with infinite distance theoretically being infinitely bright. As you experienced, this is a nightmare for clipping.

A disparity map stores the inverse depth. In other words, instead of dividing your depth by some crazy large number, you can simply output 1/(1+depth). An interesting tradeoff here is that your depth 'resolution' decreases with additional distance when using a disparity map.

  • 1
    $\begingroup$ The Mist pass trick is interesting! However, it will not work if you have objects with Volume Scattering in your scene as it will be included in the Mist pass. $\endgroup$ – Bruno Feb 23 '18 at 13:02
  • 1
    $\begingroup$ Thanks for your answer. The mist trick is not going to be useful for me at all, especially due to the anti-analising effect. $\endgroup$ – Amir Feb 23 '18 at 16:09

A white looking depth map is correct! Think about it: it captures the depth values from 0 to infinity. I believe blender works with floats so infinity is actually the largest float.

So, it makes sense for any foreground objects in your scene, which are relatively close to the camera, to have very low depth values. It means it is encoded with very little contrast in the depth map compared to the far background. Since an image is displayed on your screen with RGB values with 8bit luminance range, the "infinity" float range has to be compressed in 256 values range, thus the white image.

One way to only select the interesting foreground in the depth map is to clamp and normalize its values before display or before conversion to a low dynamic range component image. This can be achieved in the compositor using simple math nodes and clamp to desired farthest depth value.

  1. Enable depth path in your render layer
  2. Enable node for the compositor
  3. Flow the depth map into the clamp and normalize nodes then into a viewer node (sorry no screen shot or exact node setup, I am far from my computer at the moment!)

Note that you might want to clamp the lower value as well if there's nothing interesting in the foreground.

ex including clamping fore and backgrounds using color ramp in constant mode. Simply slide the color to the desired "distance":

enter image description here

  • $\begingroup$ Is it possible to somehow enforce a limit on how far the depth rays should travel? For instance, only 1 meter? I do not want to capture anything beyond a some point $\endgroup$ – Amir Feb 23 '18 at 14:16
  • $\begingroup$ Yes, added a screen shot and note to my answer, check it out. $\endgroup$ – Bruno Feb 23 '18 at 15:21
  • $\begingroup$ I'm not able to create the ColorRamp node the way you have created it. Could you please give me some instructions on how you did this? Also, how can I make sure naturally no depth rays comes into the camera beyond a certain point in the scene? Currently, I have a feeling that what you are doing is to somehow clamping the depth values. But I do not want any depth information to get discarded, no matter what. $\endgroup$ – Amir Feb 23 '18 at 16:42
  • $\begingroup$ The normalization is not doing any clamping, right? So if I normalize the depth data and store it on disk, I should be able to map everything back to the scene with 32-bit floating point accuracy. Is that right? $\endgroup$ – Amir Feb 23 '18 at 16:43
  • $\begingroup$ I feel the color ramp node and the multiplication are somehow transforming the raw depth values. If that is the case, I do not want that. $\endgroup$ – Amir Feb 23 '18 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.