Applying depth of field in compositing
True 3d depth of field can be very expensive in mental ray for Maya. That’s why 2d approach
is used whenever is possible. For this tutorial I created simple scene with two rocks in
the desert. I turned on sun and sky. I recommend you to see my tutorials for sun and sky
first.

I applied gamma nodes to textures, because sun and sky applies gamma 2.2. Gamma 0.454 bring
textures to normal look.

Also I changed filter to get crisper image.


To make render layers in Maya, use render layers panel (in channel box). Select geometry
you want to be in layer, and hit add selected button.

Right click on new layer, there’s presets submenu. Select occlusion. Shader will be
automatically applied to geometry. Notice that there’s actually two layers. Master and the
one you created. Master is always there but it is not visible when there’s no other layers.

Notice that some attributes in render settings are orange. That is layer override. When you
want to change some attribute just in one render layer, use layer overrides. In that way
you can have different settings for every layer, even different renderer. Here I made layer
override for final gather option, and turned it off.


Also for sun and sky

And for mia_exposure

Render should look like this. If you don’t change settings for exposure node, render will
look gray.

Make another layer, this time use luminance depth preset.

You should get preview in viewport.

Render should look like this

Also set layer override for image format in z_depth. Set image format to IFF16 (16 bit), it
is good to render 16 or 32 bit depth channels, to avoid artifacts. To render everything use
Batch render, even if you are rendering only one frame. Normal render to render view always
renders to 8 bit. Use (R) in render layers to set all layers to renderable.

Now compositing. I did this in fusion, but I will not bother you with interface, this
should work in any compositing app. For start I loaded images.

Notice that images have alpha channel, and that ambient occlusion have black background.
That means that sky will get black in multiplication. We want to turn sky to white.

So I layered ambient occlusion over white background.

For z_depth I make sure that image will be 16 bit.

Also I used curves to shrink ambient occlusion, to get smaller shadows.

Then I multiplied beauty render with ambient occlusion. I lowered blending to 30%.

In fusion to add zdepth channel to flow. You need to use channel booleans node (reorder in
shake). Here I eliminated alpha by setting it to white (1).

In aux channels I turned on z buffer. I used red channel from z_depth file (green input).

In fusion there’s node depthBlur (zblur in shake). You need to lower numbers, because our
render from Maya is 0 to 1. Sometimes when you render to 32 bit, image can have real
distances over 1. I made adjustments to get depth of field I want.

Also I animated focal point parameter to change depth of field over the time.

Take a look at movie I rendered. To do this in 3d, it would require to render every frame.
Here you rendered only 3 images.