How to add depth of field using a zdepth pass

Brief introduction
Depth of field can prove to be a very effective way to add a “special” touch to an architectural rendering, or simply to focus the composition on a specific element.

Technically speaking, there are several possibilities to add dof to an image.
One way to do this is to add it from the vray camera rollout (if you are using vray), but keep in mind that the rendering times can go through the roof, so unless you have a render farm you may not want to consider this option.

Another way to achieve this type of effect is by adding it from the “effects” tab in 3d max. Even if this is way faster (being just a post-processing effect) I always feel the need to have more control over it regardless of the camera position or direction.

Rendering a separate zdepth pass
So here’s the way I do it.
Under “Render Elements” click “add” and choose “vrayZdepth” (if you not with vray you can chose Zdepth instead of vray z depth, or the equivalent of your rendering software).

After hitting “render” you will notice that you end up with 2 rendered images, the main image and another one in gray scale. If you look closer at the gray scale rendering you realize that objects that are close to the camera are light gray, and they get darker as the distance between them and the camera increases.


Post processing the zdepth pass
Open both renderings in photoshop.
Select the main rendering and duplicate the “background” layer. With the newly created layer active, click on “layer” drop down menu (at the top, between “select” and “image”), click “layer mask” and select “reveal all”.

Select the grayscale rendering and invert it (image>adjustments>invert). Now using the “rectangular marquee tool” drag a selection over the entire image than press “ctrl+c” in order to copy it to the clipboard.

Select the first image again and click the “channels” tab. Activate the previously created mask (under RGB, red, green and blue channels) and press “ctrl+v” in order to copy the zdepth mask.

Click the “layers” tab and select “background copy” layer to make sure you have the layer itself activated (and not the mask).

Go to “filters” and apply a lens blur filter.
As you will notice, thanks to the zdepth mask, the lens blur is affecting more the objects that are further away, and has less effect to the ones closer to the camera.

The big advantage of using this method is that you can control the depth of field anyway you want, simply by editing (painting) the zdepth rendered pass.
Here are 2 examples that show the flexibility of this method.
Click the renderings to view higher res ones:

Tagged , , ,
3 Comments
  1. manwithnoname says:

    nice brief totorial, precisely what I needed. Thanks :)

  2. Radek says:

    Really Thank You

  3. Iván says:

    Thanks! that’s exactly what I needed! :)

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>