Getting the depth buffer

I am trying to get the z-buffer of a scene. I have a hand mesh (.obj) that Ive imported into Blender 2.57 and I cant seem to find the right way to extract an accurate depth map.

Is there a good way to do this so that I get a full range of depth values?

Here are two options:

  1. Use the Compositor in Blender: run the “Z” output straight into the Output’s “image” input. That will give you a 32-bit z-depth image that runs from your camera’s near-clip (black) to far-clip (white) values. Note that you’ll need to render to a 32-bit format, such as EXR, if you want to use it later on. You can also use nodes to produce a visually meaningful depth map (where you see the grayscale info); for instance you can run the Z info through a “normalize” node. Example attached.

  2. Render to EXR and check the “zbuf” option. This includes the 32-bit z-depth along with the image in a single EXR image, though you’ll need to know how to extract that data later on (After Effects has ways to do it, for instance).

Attachments

zDepth_via_compositor.blend (446 KB)

Hi, Benu! Can you check this file? I’m not sure it deserves a bug report or not… I checked everything and can’t get what’s wrong… I suppose that it’s something with render layers (in Compositor) I had Input Render Layer with the blank field (that was probably after I deleted some Render Layer (in Layers) so the Input become orphanted. I get the white screen instead of Z. It’s really frustrating. Your file renders well. It’s not very critical but if you can figure out something, please answer.

Attachments

zBuffer_Corrupted.blend (426 KB)

Actually the z-depth data is in there, but it’s contained in a 32-bit image, and you’re only seeing a limited range of that image. As I suggested earlier, try running it through a “Normalize” node, which will sample the darkest and lightest values and “stretch” the blacks and whites to fit nicely into an 8-bit image:


Keep in mind that this will dynamically update, which means if your camera moves closer to the box (or the box closer to the camera) the z-depth info will look more or less the same. If you want to manually set the range of z-depth representation, fiddle around with the “Map Value” node:


Basically, the “Offset” determines where you “center” the depth, and the “Size” determines how much range will be used to fill the grayscale range (smaller numbers equal a larger range). Good luck!

Thanks guys! Great explanations! Now I nailed the issue with your help.