Custom Depth Pass in XSI
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  to switch to the Render toolbar and from the Pass > Edit > New Pass menu choose Empty. Name the pass Depth_Pass. Press  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  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:
By saving the material as a preset, you can easily create depth passes in future projects within a few mouse clicks.