Tutorial: Depth of Field

Tutorial: Depth of Field

To get started, let's open the Maya scene, depth_of_field.ma.

(Where are the tutorial files?)

1. Analyzing the Scene

Open the scene, depth_of_field.ma, in Maya. For this tutorial we have numerous stacks of boxes piled up around the scene. We will use depth of field to create a focal point for the scene. RenderMan uses an advanced 3D depth of field that is quite accurate. RenderMan's depth of field is not a post-process effect. Expect RenderMan to give you depth of field that has accurate anti-aliasing and placement.

First render the Maya scene without depth of field. Make sure your renderer is set to RenderMan:

Render-> Render Current Frame

You should get an image like the one below:

images/dofNoDof.png

Stacks of Boxes, No Depth of Field

2. Enabling Depth of Field

Next we'll enable depth of field. We can enable depth of field simply by using Maya's depth of field controls. Just open the main camera in the Attribute Editor and enable the effect by clicking on the Depth of Field check-box. Now Render the Maya scene:

Render-> Render Current Frame

You should get an image like the one below:

images/simpleDof.png

Depth of Field enabled

3. Adjusting Pixel Samples

For RenderMan, after Shading Rate, Pixel Samples is the most important quality setting for depth of field, especially extremely blurry depth of field. In the image above the depth of field is rather "grainy", which is undesirable. By increasing the pixel samples we can create a smoother effect. We can increase Pixel Samples by opening the Render Globals and selecting the Quality tab. The Pixel Samples setting defaults to 3x3. Increase the Pixel Samples to 12x12 (which will cause RenderMan to sample each pixel many more times). Now render the scene again:

Render-> Render Current Frame

You should get an image with much smoother depth of field - note especially the difference at the edges of the boxes:

images/12x12Dof.png

Depth of Field with "12x12" Pixel Samples

4. Motion Factor vs. Focus Factor

Motion Factor is a control used to render motion-blurred objects more efficiently. Motion Factor is a multiplier for the shading rate and allows the renderer to use a lower quality shading rate for motion-blurred objects, assuming that if stuff is moving, it needs less detail. In earlier versions, the Motion Factor setting affected both motion blur and depth of field, but RfM now provides a separate Focus Factor setting specifically for depth of field calculations. In our particular case here, we don't want any Focus Factor optimizations because we want to retain the detail in the textures on our boxes, so we'll set Focus Factor to "0". Open the Quality tab of the Render Globals and set Focus Factor to "0" (the default value is 3). As we mentioned above, however, this setting is a multiplier for Shading Rate, and 5.0 is still a failry coarse shading rate, so let's lower that, as well, to 1.0. Now render the scene again:

Render-> Render Current Frame

You should get an image with more detail in the textures. You'll notice the text is clearer:

images/dofNoFF.png

Depth of Field with Shading Rate of "1" and Focus Factor of "0"

In addition to separate Motion and Focus Factor settings, you can explicitly add Motion/Focus Factor attributes to individual surfaces, so any surface can have its own setting. To add attributes, select the surface and add the attribute from Maya's Attribute Editor.

  1. Attribute Editor: Attributes-> RenderMan-> Manage Attributes
  2. In the pop-up window, select and add focus factor.
  3. Focus factor will now appear under the Extra RenderMan Attributes sub-tab, ready for adjustment.

5. Summary

RenderMan renders true 3D depth of field, which ensures correct anti-aliasing and positioning of the depth of field effect. It is not a post-process effect. By increasing the Pixel Samples, higher quality depth of field can be created, but, to avoid excessive render cycles, Pixel Samples should only be increased as much as is required.