How to Render and Composite a zDepth map from Autodesk Maya

In this tutorial I will show you how to render a zDepth Map from Autodesk Maya 2016 Ext 2 or higher and how to composite it in Nuke.

I have linked all the example files below, but I strongly encourage following this tutorial so you will know how the system works and can adapt it.

Software you will need:

  • Autodesk Maya 2016 Extension 2 or higher
  • Nuke 10 (non-commercial works too)

Setting up the Scene

You do not need to start with an empty scene. If there’s already animation/lighting/vfx in the scene does not matter.

  1. Open your 3D scene in Maya and open the Render Setup window (In Windows -> Rendering Editors -> Render Setup)
  2. Create a new Render Layer, and rename it to “Color”
    1. Right-click the layer and add a new collection
    2. Name it “Elements”
    3. In the outliner, select all your geometry and lights
    4. In the Property Editor of the Render Setup window, click the [Add] button.
  3. Create a new Render Layer and rename it to “zDepth”
    1. Create a new collection, rename it to “Geometry” and add only the geometry of your scene to it
    2. Create a new collection, and add all of your lights to it
    3. Disable the collection containing your lights (this way they don’t shine and mess up the depth map
    4. In the Outliner, go to Display -> and uncheck “Show DAG shapes only”
    5. type “rs” into the search box and select the “rs_zDepth” entry
    6. In the Attribute Editor, Click Presets and click “Luminance Depth”
    7. A Surface Shader has been created, and the attribute editor should have switched to it. If it did not automatically switch, go to the Hypershade (Windows -> Rendering Editors -> Hypershade) and click the Surface Shader. Click the black triangle-box next to [Color]
    8. The Attribute Editor should have switched to a setRange node screen. Right click “Old Min” and “Old Max” and break the connections
    9. “Old min” is the value that determines the closeness of objects. Leave this value alone.
    10. “Old Max” is the number of units before the depth map becomes completely black. For My own scene, I set this t0 250.
    11. Switch back to the Render Setup window. Right click the “Geometry” collection and select “Create Material Override”
    12. Open the Hypershade window (Windows -> Rendering Editors -> Hypershade)
      1. Select the surfaceShader, and middle-mouse drag it to the Override Material box in the Render Setup View
    13. Click the eye icon on the zDepth layer to make it visible. All the objects in the scene should have a white-to-black gradient. Move the camera to see it update.
    14. Play around with the “Old Max” value and try to make the 100% black area be just at the far edge of the scene.
  4. (Optional, but looks really good) Create another Render Layer and rename it to “Fog”
    1. To create the objects for the fog pass,
      1. create a volume cube and encompass your whole scene with it.
      2. In the cubeFog properties, assign a Cloud texture to the transparency attribute. You don’t need to change anything about the fog pass.
    2. Create two collections for the Fog layer: “Fog_Object” and “Disable_Lights”
    3. Add your volume box to the “Fog_Object” collection
    4. Add all your lights to the “Disable_Lights” collection, and then disable the collection.
    5. Click the Eye to make the Fog Layer visible. You should only see the volume box and nothing else.
  5. In the Render Settings window, click the clapboard next to the default “Scene” render layer to disable it. (It should not be blue)
  6. Set up your render settings how you like (I’ve found Mental Ray to create the best depth map), and render your scene!
    1. Make sure that the Depth pass does not render a colored background (have a transparent background)
    2. It should create 3 folders in the images directory: “Color” “zDepth” and “Fog”, each containing the correct data.

Compositing the scene

You are done with Maya now. Make sure you like the output of your three image sequences before continuing to the next steps.

If you prefer a different compositor and know how to composite the depth, then you can skip the rest of this document.

The Basics of Nuke:
Creating nodes in nuke: 
Right Click in Node graph -> find node OR Press tab -> search for node
Connecting nodes: 
Click and Drag the arrows on top of compatible nodes
Editing Nodes: 
Double-click on node to open property panel, then drag sliders to modify values.
Close Node: Press the [x] at the top right of the node property panel (next to the ? and Window buttons)
Disable Node: Click on the node and press [D] on your keyboard

  1. Launch Nuke, and create a new project.
  2. Go to Edit -> Project Settings (or press [S] on your keyboard)
    1. Set frame range so it matches your image sequences, then close the panel
  3. Drag your image sequences from the file explorer into the project viewer (or import them from File -> Import File(s))
    1. They should have rendered into 3 folders: “rs_Color” “rs_zDepth” and “rs_Fog”
  4. Click the Node Graph tab at the middle-right of the window
  5. Drag your sequences from the Project viewer into the node graph
  6. In the Node Graph, create a ShuffleCopy node
  7. Connect the (1) to the Color sequence and the (2) to the Depth sequence
    1. Set the properties as follows:
  8. Create a Constant node, and set it to any color that’s not black
  9. Create an AddMix node, and connect the (A) to the Constant, and the (B) to the Fog sequence
  10. Create a ZMerge node, and connect the (1) input to the AddMix node and the (2) Input to the ShuffleCopy node
    1. Z channel: depth.Z
    2. Alpha channel: depth.Z
    3. smaller Z = further away: checked
  11. Create a ZDefocus Node, and connect the (Image) input to the ShuffleCopy node
    1. math: depth
    2. blur inside: unchecked
  12. Create a Merge node, and connect the (A) input to the ZMerge node and the (B) input to the ZDefocus node
    1. Decrease mix to around 0.225
  13. Connect the Viewer input to the Merge node.
  14. Your node graph is done! Connect any extra nodes for further compositing to the Merge Node

Tweaking the setup:

To change how the different nodes interact, change the following values:

Depth of Field distance: In the ZDefocus node, change the Focus Plane attribute. Larger values = closer blurring
Alternatively, you can drag the focal_point handle in the viewer to interactively set the focus plane.

Depth of Field strength: Change the size value of the ZDefocus node.

Depth of field end strength: Change the maximum value of the ZDefocus node.

Fog Color: Change the color of the Constant node. If you want the color to be something else, just replace the Constant node with a different setup. Just make sure the final output of that setup outputs to the (A) input on the AddMix node.

Fog Density: Change the mix value of the AddMix node

Fog Distance/Intensity: Change the mix value of the Merge node (Not the ZMerge node!)


Rendering the final composite

To export your composite as a video file or as an image sequence, do the following:

  1. Create a Write node and connect the input to the Merge node (if the viewer is already connected, just drag the Write node over the dashed line)
  2. For a Video output
    1. file type: mov
    2. Codec: h.264 (if present) or Apple ProRes 4444
  3. For an image sequence output
    1. file type: select any image format (I recommend .exr or .tiff for preserving ultrawhite values, or .png for regular clamping.
    2. To render the alpha channel, set channels to rgba
  4. Click the folder icon next to file and select a folder to write the file in (make sure to include the extension!)
  5. To exclude the DOF disable the ZDefocus node (optional)
  6. Go to Render -> All Write nodes (or press F5 on your keyboard)
  7. (Optional) check render in background, set the frame range if incorrect, and press [OK]
  8. Wait for the render to complete (this can take a while on slow hardware)

Congratulations! You have successfully composited depth from Maya using Nuke!

If you want to suggest edits, or another tutorial, comment it down below (you do not need to register to comment)

Download the example files

Note: the .mb file requires Maya 2017 to open without errors.


Leave a Reply