Caffeine Abuse - The Blog

Custom Depth Pass in XSI


There are a couple of different ways to create depth passes in XSI, including the pre defined that can be found in the Render > Pass > Edit > New Pass menu. Since it’s only a mouse click away, it’s obviously the quickest to create. However, finding the proper values may not be the most intuitive with this setup.

Open the scene depth_pass.scn from this issues CD, or create a scene with a couple of object on your own. Create two Null objects and name them Near and Far. Position the Near null at the pear closest to the camera and the Far null at the pear in the back. These will be used to control the gradient. The surface closest to the camera will be white and the one furthest away will be black. Press [3] to switch to the Render toolbar and from the Pass > Edit > New Pass menu choose Empty. Name the pass Depth_Pass. Press [8] to open an Explorer and press [P] to change the scope to pass. Expand the Depth_Pass node and select the Background_Objects_Partition. From the Get > Material menu choose Constant and press [7] to open a Render Tree. From the Nodes > State menu get a Scalar state node (make sure it’s set to Ray Length in the PPG) and from the Nodes > Math get a Change Range node. Connect the Scalar state node to the input of the Change Range node and the Change Range node to the Surface input of the Material node. Double-click on the Change Range node to open the PPG. By converting the position of the null objects to zero (black) and one (white), you’ll create the grayscale image. Right click on the animation icon next to the Old Range: Start and choose Expression Editor… from the menu. Enter ctr_dist_cam( Far. ) in the editing pane, click the Apply button and close the editor. Right click on the animation icon next to the Old Range: End and choose Expression Editor… from the menu. Enter ctr_dist_cam( Near. ) in the editing pane, click the Apply button and close the editor. Set the New Range: Start to 0 (zero) and New Range: End to 1. Draw a Render Region and play with the nulls’ position to see the effect.

The project files used in this tutorial can be found at:

A depth pass is basically a grayscale image of your 3d scene, where the different shades of gray represents different depths. By using null objects and a couple of nodes in the render tree, you’ll get an interactive visual representation of the near and far values of your depth pass.

Quick tip
By saving the material as a preset, you can easily create depth passes in future projects within a few mouse clicks.


  1. January 19, 2009

    handy trick. The built-in depth pass a little tricky with large scenes. One problem though, saving the material as a preset dumps all expressions. Something I’m not doing?

  2. March 30, 2009

    How would you add transparency to that mix?

  3. April 3, 2009

    Hi Vfxwolf,

    No, you’re not doing anything wrong. The preset only stores the nodes in the render tree. A quick workaround is to put the material and the null objects in a model and then export it. whenever you need to setup a new depth pass, just import the model…


  4. December 3, 2009

    Many institutions limit access to their online information. Making this information available will be an asset to all.
    Custom Paper Writing

  5. May 29, 2010

    Great tip, thanks Ola!!
    Is is possible to setup a depth pass in a scene full of leaves where a cutout map is applied to a plane in order to render those leaves properly? Or this technique also only works with geometry?

  6. October 20, 2012

    wow!!! great! thank you very much! you should continue drinking coffe

  7. March 11, 2013

    great tips!
    just one thing… is there any ways to loose the relationship with the camera?
    thank you!

  8. March 11, 2013

    Not quite sure what you mean with ”loose the relationship with the camera”. The depth pass is by design based on the objects position/distance from the camera. What is it that you’re trying to achieve? If you just want to control the color (or any other material attribute) of an object based on distance, maybe this post will help:


  9. March 11, 2013

    Thank you so much!
    that is exactly (kind of…) what i did. except mine was much simpler… or stupid-er…
    i created a new camera for a gradient camera projection. this way, i can control where the direction of gradient could be.
    ha. i guess i wasn’t really looking for depth. thank you so much for your quick response. you are the best!