Beauty render composited with Z Depth AOV (rollover image).
In this short tutorial we will cover the process of setting up and rendering out a 'Z' depth AOV from MtoA 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.
To render and composite a 'Z' depth AOV, you must do the following:
- First, open the Render Settings window and go to the 'AOVs' tab. Create a Z depth AOV. It is one of the AOVs available under the 'AOV Group'.
Z depth AOV is active
- Under AOVs, to the right of the newly created 'Z' AOV there is a downward pointing arrow. Click on that and choose 'Select Driver' from the menu.
- The Arnold driver should appear in the attribute editor. Select 'Merge AOVs'. This will combine the 'Z' AOV with the rendered EXR as one file.
Enable 'Merge AOVs' stores the AOVs in one EXR file
- Render the scene and open the EXR file in Nuke.
When viewing the depth AOV in Nuke it might only show red. The Depth channel will give you non-antialised, 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
- Connect a 'Zblur'('ZDefocus' in Nuke 7) to the EXR render and enable 'focal-plane setup'. The default setting of the Zblur node should work. Z should be set to 'depth.z' and 'math' should be set to 'depth' (the Z value in the depth channel is the distance in front of the camera).
- Adjust the 'focus plane' until the green area is where you want the area of focus to be. The red color shows the area that has less depth of field. The blue color represents the area that falls outside the depth of field area. The green color represents the area that is inside the area of depth of field. If the depth parameter is set to 0, you will not be able to see any green.
Focal-plane setup enabled (green area is in focus)
- Once you are happy with the 'focus plane', disable 'focal-plane setup'. Increase the 'depth-of-field' to one. You should now see the RGB image being blurred by the 'Zblur' node.
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, whilst looking better in most cases, can require a large number of AA samples in order 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 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.
True DOF (8 AA samples) DOF composited using Z Depth AOV
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.