Two Ways to Generate Z Depth in 3ds Max


Final product image
What You'll Be Creating
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
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
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
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
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
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
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
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
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
Pick the tape’s head and you will get its value. This is the Z Min value.
Z Min value
Z Min value
Put the value in Z Min box.
Z Min value
Z Min value
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
Put this value in Z Max box.
Z Max value
Z Max value
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
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
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
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
Click on Pick and Select Camera button. Press H to open the Pick Object window and here select the camera.
Pick camera
Pick camera
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
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
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
Open both the Diffuse and Z Depth pass renders in Photoshop.
Open Photoshop
Open Photoshop
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
Now deselect the Z Depth layer and select the Diffuse layer. Then go to Channels tab.
Open Channels tab
Open Channels tab
In the right side corner, click on the drop down arrow menu and select New Channel from the list.
New Channel
New Channel
It opens the New Channel window. Give it a name, such as Alpha 1.
Rename the channel
Rename the channel
With the Alpha 1 channel selected, press Ctrl-V to paste the copied Z Depth image.
Paste the channel
Paste the channel
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
It opens the Lens Blur window. The image look totally blurred and out of focus right now.
Lens Blur window
Lens Blur window
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
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.

TDasany

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

 

Copyright @ 2013 KrobKnea.

Designed by Next Learn | My partner