Advertisement
  1. 3D & Motion Graphics
  2. 3D Studio Max
Cgi

Two Ways to Generate Z Depth in 3ds Max

by
Difficulty:IntermediateLength:ShortLanguages:
Final product image
What You'll Be Creating

1. Z Depth With Mental Ray

Step 1

I have made a very simple scene for the demonstration. This scene contains several spheres. I have also applied some materials and set the rendering engine to Mental Ray. I have set a camera also.

Creating a simple scene
Creating a simple scene

Step 2

I have added and positioned several Omni lights in the scene. I have chosen Ray Traced Shadows as shadow type.

Ray traced shadow
Ray traced shadow

Step 3

Press the F10 key to open the Render Setup window. In the Renderer tab, set the Minimum value to 4 and the Maximum value to 16. Select Mitchell for the Filter Type.

Renderer
Renderer

Step 4

Now render the scene. It looks nice, but the depth is still missing. I can enhance the overall look by adding a Z Depth pass while compositing.

Rendering the frame
Rendering the frame

Step 5

In general words, a Z Depth pass is a grayscale image, similar to the alpha channel for the graphical representation of depth.  In a Z Depth pass, every pixel in a scene is assigned a 0-255 grayscale value based upon its distance from the camera. 

The objects closest to the camera are white and the objects furthest from the camera are black. It gives an extra sense of depth and realism after compositing. Look at the image below for a before and after comparison.

Z Depth
Z Depth

Step 6

See how I generate a Z Depth pass using Mental Ray. Press the F10 key to open the Render Setup window. In the Render Element tab, click on Add button and choose Z Depth from the list. Click on OK.

Adding Z Depth pass
Adding Z Depth pass

Step 7

Press F9 to render the frame. You can see a grayscale Z Depth pass. The objects closest to the camera are white and the objects furthest from the camera are black.This is not the correct Z Depth pass as I don’t know the exact distance between the camera and the objects in the scene.

Z Depth pass rendered frame
Z Depth pass rendered frame

Step 8

To know the exact distance between the camera and the objects, Z Min and Z Max values will help. Z Min defines the distance between the camera and the closest object. And Z Max defines the distance between the camera and the furthest object.

Z Depth element parameters
Z Depth element parameters

Step 9

To measure the distance, I need a tape. So, go to Helpers > Tape and draw a tape from the camera to the closest sphere.

Using tape
Using tape

Step 10

Pick the tape’s head and you will get its value. This is the Z Min value.

Z Min value
Z Min value

Step 11

Put the value in Z Min box.

Z Min value
Z Min value

Step 12

Pick the target of the tape tool and put it beside the furthest sphere from the camera. Pick the tape’s head and you will get the Z Max value.

Z Max value
Z Max value

Step 13

Put this value in Z Max box.

Z Max value
Z Max value

Step 14

Press F9 to render the frame. Now you will get a perfect Z Depth pass along with the Diffuse pass.

Final Z Depth pass
Final Z Depth pass

2. Z Depth through MAXScript

Step 1

Michele Marcelli has written a very useful script for creating Z Depth. You can go to www.scriptspot.com to obtain the script. The best thing about it is that the script is free to use.

Free script
Free script

Step 2

Download and install the script. Normally you have to put the script into the Scripts folder of the 3ds Max root directory.

Install the script
Install the script

Step 3

Back in 3ds Max, go to MAXScript > Run Script. This opens the browser, select the script and click on Open. This opens the script’s window.

Run Max Script
Run Max Script

Step 4

Click on Pick and Select Camera button. Press H to open the Pick Object window and here select the camera.

Pick camera
Pick camera

Step 5

Click on Preview Z-Depth (Selected Camera) button. Within a couple of seconds, you will see a preview of Z Depth pass in the preview window. The output result looks good, but a bit grainy. So I need to tweak some values.

Preview Z Depth
Preview Z Depth

Step 6

You can play with the Z Min and Z Max values to get the desired Z Depth pass. Each and every time you need to check the pass clicking on the preview button.

Z Min and Z Max
Z Min and Z Max

Step 7

Once you are satisfied with the preview, click on Render VFB button. This will show you the final result.  

Final rendered frame of Z Depth pass
Final rendered frame of Z Depth pass

3. Compositing

Step 1

Open both the Diffuse and Z Depth pass renders in Photoshop.

Open Photoshop
Open Photoshop

Step 2

With the Z Depth layer selected, press Crtl-A button to select the entire image and then press Ctrl-C to copy the image.

Copy the Z Depth image
Copy the Z Depth image

Step 3

Now deselect the Z Depth layer and select the Diffuse layer. Then go to Channels tab.

Open Channels tab
Open Channels tab

Step 4

In the right side corner, click on the drop down arrow menu and select New Channel from the list.

New Channel
New Channel

Step 5

It opens the New Channel window. Give it a name, such as Alpha 1.

Rename the channel
Rename the channel

Step 6

With the Alpha 1 channel selected, press Ctrl-V to paste the copied Z Depth image.

Paste the channel
Paste the channel

Step 7

Go to Layer panel once again. Now, with the Diffuse layer selected, go to Filter > Blur > Lens Blur.

Apply Lens Blur filter
Apply Lens Blur filter

Step 8

It opens the Lens Blur window. The image look totally blurred and out of focus right now.

Lens Blur window
Lens Blur window

Step 9

Select Alpha 1 as the Source channel and set the Blur Focal Distance to 255. Now you will see an extra realm of depth in the scene as some part of the image gets blurred partially and rest of the part remains in focus. This happens due to the Z Depth pass.  You can easily control the amount of the focus and area of focus with the parameters of the lens blur effect.

Setting the parameters
Setting the parameters

Conclusion

I hope you have enjoyed these ways to create Z Depth pass in 3ds Max. The script written by Michele Marcelli is the fastest way to get the Z Depth pass. The script is totally free to use, however if you find it useful, you can donate an amount to the creator of the script as a return gesture. This is only a matter of choice.


Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.