Z Depth AOV

Beauty render composited with Z Depth AOV

In this short tutorial, we will cover the process of setting up and rendering out a 'Z' depth AOV which can then be composited with the beauty render in Nuke to achieve a realistic depth of field effect. The 'Z' depth AOV contains the depth information of the shading points.

The scene can be downloaded here.

To render and composite a 'Z' depth AOV, you must do the following:

Enable 'Merge AOVs' stores the AOVs in one EXR file

If you open your multilayer EXR in Photoshop it must be done in 32-bit as converting it to 8-bit will lose all of the depth info. The Z depth image is unclamped, so it may appear pure white. Go to Image -> Adjustments -> Exposure and adjust the exposure until you get something that looks like a regular z-depth pass.

When viewing the depth AOV in Nuke, it might only show red. The Depth channel will give you non-antialiased, non-normalized depth data in the alpha channel. Non-normalized means that the Z depth values are not between 0 and 1 (distance in front of the camera), so you must divide the Z values by the far clipping plane value to get 0..1 values. This remapping is only required when viewing the depth channel in the viewer. It is not needed to make the zdefocus node work.

Z depth channel viewed within Nuke

Focal-plane setup enabled (green area is in focus)

That concludes this short tutorial. The benefits of using a Z Depth AOV are obviously speed and flexibility. Being able to make changes to the depth of field in the compositor in real time is a big advantage. Rendering with true depth of field, while looking better in most cases, can require a large number of AA samples to resolve issues with noise. Below is a comparison between rendering true depth of field and rendering the scene without DOF (using a composited 'Z' depth AOV). Even with 8 Camera (AA) samples, there is still some noise in the heavy depth of field areas of the image rendered with true depth of field. In this case, the render with true DOF took about twice as long to render as the image using a Z Depth AOV.

DOF composited using Z Depth AOV True DOF (8 Camera (AA) samples)

Limitations

There are limitations to using a 'Z' depth AOV. For example, it is not possible to focus on an object reflected in a mirror (see below):

Focusing on an object in a mirror is not possible using a 2d 'Z' depth AOV (above image rendered with true depth of field).

3d scan model courtesy of Ten24 .