This tutorial shows 3 different methods to create height and depth grayscale representations of a maya scene, which may be useful in many cases such as adding depth of field or fog in post production.
First Method:
1.Create some spheres, and post them on different distances from the camera. Assign a material to the spheres, such as a simple lambert material (to make the result independent from the lights in your scene, use in all the methods a surface shader). When rendering at this stage, all the spheres have the same color, independently from the distance from the camera.
2. Go to the Attribute Editor of the material, and map its color with a ramp. In the Create render node dialog, make sure that As Projection is selected, and choose a ramp.
Edit the projection node by choosing planar as the projection type, and make the ramp a black and white 2 colors ramp.
3. The projection icon is now visible in the viewport, as a small rectangular shape. Scale that icon to fit your scene entirely. Take a render of the scene. The color of the spheres must now be fading towards black. If it is not the case, you will have to change the ramp type from U ramp to V ramp or vice versa.
4.The 2 main limitations of this method are:
If you move the camera away from the spheres, their color remains unchanged when rendering.
If you render the scene from the opposite side, the colors also remain unchanged, so that the closest sphere is dark, while the farthest sphere is clear.
This method is suitable for a static scene, where the place of the camera is already decided, because the result here is static, so it’s not suitable for moving cameras. The problem can be solved by parenting the projection icon to the camera, but here another problem arises: the scene might fall out of the range of the projection icon, which will lead to unexpected results.