← Learn library

VFX & Production / Houdini & Procedural Workflows / Houdini

Learn How to Render and composite Z-Depth in Houdini

Channel: CGI Nerd ·

Written guide

Original CGI Nerd video thumbnail
Learn How to Render and composite Z-Depth in HoudiniCGI Nerd · Video hosted on YouTube

Playing loads YouTube content. YouTube processes data after activation.

Watch on YouTube

If the player is blocked or unavailable, use Watch on YouTube.

Software: Houdini

A depth pass stores information that can drive selective blur after rendering. This lesson exports Mantra’s Pz image plane to an EXR, reads it in Houdini’s historical compositing network, generates a focus mask, and uses that mask to defocus the original color image.

The exact Houdini release is unverified. The nodes shown belong to the older compositing workflow; no migration to a newer compositor is demonstrated. This is a two-dimensional depth-of-field treatment of the rendered image. For the separate camera-and-renderer approach, see the Mantra depth-of-field lesson.

Export the depth plane with the color image

At 00:02, create or select a Mantra node in the output context. Under Images and Extra Image Planes, enable Shading Depth (Pz). The recording shows other render components in this area, but this exercise needs the depth plane in addition to color and alpha.

Render to MPlay. Use the plane selector to inspect RGB, alpha, and Pz separately. A successful beauty render does not prove that the extra plane was exported; confirm that Pz exists before moving into compositing.

Around 02:03, use the Point Inspector to read depth values at different image locations. The example contains values around 45 and 48, with much larger values farther away. Depth is data, so the grayscale display should not be mistaken for a requirement that every value lie between zero and one.

The narration contrasts these depths with RGB samples in its particular image. That is not a general limit on floating-point color: OpenEXR can also store color values above one. Its technical introduction describes the floating-point channel types and scene-linear color range. Preserve the data rather than normalizing the saved depth simply to make it easier to view.

Save the rendered frame as an .exr. The demonstrated output is a single frame; sequence handling is not developed in this recording.

Read the saved file and inspect values behind a white preview

From 04:02, create a File node in the compositing network and open Composite View. Check the path carefully: the node initially points to an earlier test image, so the instructor replaces it with the newly exported file.

Verify that color, alpha, and Pz remain available after readback. The depth plane can look completely white in the viewer even though the inspector shows different numerical values. Use Adapt to Full Pixel Range to display those differences more clearly.

That viewer adjustment helps inspection; it is not evidence that the underlying depth values have changed. Sample the intended subject to choose a focus distance from the actual depth data. The instructor first selects a region with a value around 45.

Generate a mask, then use it in Defocus

At 06:04, add a Depth of Field compositing node and set Focus Distance to the sampled value. The color image does not immediately blur because this node is used to create the focus-related mask for the next operation.

Add Defocus. Connect the original image to its image input and the Depth of Field result to its mask input. Inspect the planes after Depth of Field: in addition to the existing channels, the node has created an M mask plane from the depth information.

The first Defocus result blurs the whole image. Its mask setting is reading alpha instead of the new focus mask. Change the mask plane to M. Then enable Per Pixel Defocus, which is another necessary setting in the demonstrated setup.

Both corrections matter. Merely connecting a mask input does not guarantee that Defocus selects the intended plane, and selecting M without the demonstrated per-pixel option still leaves the setup incomplete. Verify the plane and the option before compensating with extreme blur values.

Refine the focus range and check the selected depth

Around 09:03, adjust the Defocus amount and the Depth of Field node’s Depth Adjust control while watching the result. The instructor works back and forth between them to change blur strength and the range that remains acceptably focused.

To move attention elsewhere, inspect Pz again. The next selected region has a value around 33, so Focus Distance is changed to 33. The recording briefly enters 300 or 333 by mistake and corrects the field. If the result jumps to an unexpected depth, inspect the typed number before assuming the mask wiring has broken.

The final example leaves a middle region clear while foreground and background areas soften. Check the color result as well as the mask: a convincing-looking grayscale image is only an intermediate diagnostic, not the finished composite.

The lesson demonstrates this single-image workflow and its missing-plane/per-pixel corrections. It does not compare the result against a physically rendered aperture, test moving sequences, or resolve every artifact around transparency and overlapping depth layers. Within that scope, the reliable chain is explicit: export Pz, verify it on readback, choose focus from sampled depth, generate M, and configure Defocus to use that mask per pixel.