Post DOF vs Rendered DOF

Although it’s far more common to render 3D images without Depth-Of-Field (DOF) as it renders quicker and offers some flexibility in compositing. In some situations that isn’t always the case as large ZBlur’s within Nuke can take a heck of a long time to render. In fact depending on your scene and your renderer it’s often quicker to render DOF in 3d than it is to apply it as a post process in 2d.

Post DOF

  • Flexibility in compositing. Can adjust effect as needed.
  • Quicker to render.
  • Can be inaccurate – no physically based parameters (although this is largely dependant on the plugin used. The effect is driven by the artist.
  • Large blurs are slow to render.
  • Prone to artifacts. Can’t handle certain situations at all without lot’s of hackery.

Rendered DOF

  • No Flexibility in compositing.
  • Slower to render.
  • Accurate. Physically based parameters.
  • Requires more pixel samples in order to avoid noisy renders.

The following render was done at 2048×1556 and was rendered without any DOF. The total render took 83 seconds. The Depth AOV was rendered using a Zmin filter with a filterwidth of 1×1 in order to avoid anti-aliasing in the render.

Click to see full resolution.

I also rendered the same image with DOF on.

Click to see full resolution.

Unfortunately my plan to show the difference between the two full resolution images was put on hold by Nuke taking far too long to render the full resolution ZBlur. I gave up after 10 minutes so decided to concentrate on a particular region.

Crop region used.

The following 1:1 crop demonstrates the difference between Post DOF and Rendered DOF.

Keep in mind that the Nuke time for the Post DOF was only for the crop area your seeing above – it was taking too long to render the full image with Post DOF. As you can see the Post DOF breaks down quite heavily in some places, while the rendered DOF image did take longer to render, it’s much more accurate and the read time of the image is less than a second in Nuke.

Observations…

  • The rendered DOF spent less time ray-tracing and more time spent on sampling the image. This was due to the increase in pixel samples in order to get less noisy results and higher focus factor.
  • With pixel samples at 3×3 the DOF render took 57 seconds, faster than the 83 seconds that it took to render the Non-DOF version although the final result was unacceptable. For less extreme blurs pixel samples could be set as low as 6×6.
  • Focus Factor parameter in 3Delight helps speed up DOF renders by reducing the shading rate in areas of high blur with very little perceivable difference.
  • Despite some noise, the end result is much more visually pleasing than the ZBlur result in Nuke.

 

 

Screenspace Texture Mapping in Maya/Mental Ray

Screenspace mapping or to be more geeky Normalized Device Coordinates  (NDC) mapping allows you to map a texture according the screenspace coordinates rather than use traditional UV coordinates.

The example below shows traditional UV mapping on the left and screenspace mapping on the right applied to a flat plane inside Maya (see middle for what the camera is seeing).

This technique was used in ye olden’ days (it started getting phased out around 2006-2008) inside Renderman shader to composite occlusion renders with beauty renders. The occlusion would be rendered out in a prepass and then composited during the beauty render.

You could also use this technique to do 2d compositing or even just general purpose image processing inside Maya.

The method of doing this is slightly different between Maya Software and Mental Ray, in order to do this in Mental Ray you need to use a mib_texture_vector and mib_texture_filter_lookup, the shading network looks like this…

The settings in the mib_texture_vector need to look like this…

With Maya Software the shading network looks like this…

The projection settings should look like this…

Note that the camera should be the one your rendering from if you want the mapping in screenspace, otherwise this will act like a camera projection (it is a projection node). One final caveat with Maya Software is that you’ll need to delete the UVs on the geometry in order for this to work. If you want to switch between UVs and no UVs, apply a Delete UVs node and set the node behaviour to HasNoEffect when you want UVs and set it to Normal when you don’t want UVs.