Controling and Smoothing Depth of Field in Maya


We’ll see how the image below changes as Depth of Field parameters are altered. We’ll then take a look at smoothing the depth of field because the default maya DoF makes the render look very grainy.


If you select a camera and open up the attributes editor there is a Depth of Field tab. Expand that and tick Depth of Field to turn it on.


For the Focus Distance, set that value as the distance of the subject from the camera. You can find that out by going to Display –> Heads Up Display –> Object Details and selecting the object while viewing through the camera; the distance appears in the top right corner of the viewport in green. In this case, the distance of the front macaroon from the camera was 5.693 so I set the Focus Distance to 5.

Keeping the Focus Region Scale value of 1 and F Stop at 8, the render turned out like below.


Increasing the F Stop value makes the background not blur as fast. This is a bit of trial and error for me. But I take it as; the smaller the value, the faster the camera blurs beyond the focus distance. Increasing the F Stop value from 8 to 20 made the render look like below.


Increasing the Focus Region Scale to 2 lessens the blur behind the focus distance.


The default Depth of Field renders out quite horribly; the blurring is very noisy. Increasing the anti-aliasing in render settings doesn’t help much either.


A great way to fix this is to create a Lens Shader in the camera attributes.

When you hit on Create in the Lens Shader section of the camera, select physical_lens_dof.



Then enter the Mel script “addAttr -ln "dofLensSamples" -at "short" mentalrayGlobals“.
Then type “select mentalrayGlobals” in the Mel script area so it shows up in the attributes window. Increase the Dof Lens Samples. This smooths out the depth of field blurs.


The default Plane parameter value was -10, which rendered out like this.

By changing the Plane value to -6 (which was approximately the negative of the Focus Distance), the render focused on the front macaroon again.



Compare the difference below. Left is what it looked like before with the default Maya depth of field, and the right is after the lens was created and samples were increased.



9 Comments Add yours

  1. Tomas says:

    Very well explained!

    1. Annie says:

      Hi, I was wondering if you may help me? :) Where do i add in the mel script? :( supposedly I tried and its not working for me.

  2. Joshua says:

    Thank you. I hated the way the DOF on he camera worked. It was frustrating me getting a good render. I am happy now

  3. Anonymous says:

    where do you add in the mel script? :( Im super confused in that one area.

    1. Anonymous says:

      in maya 2014 it is in a little box down at the bottom of your screen, under the timeline, not sure if this is the same on other versions, since I am new to maya

  4. James Pero says:

    Hello, I’m trying to add the lens, but my Lenses tab only has 3 shaders to pick from and the one used in this tutorial is not listed. Any ideas on how to get it into my shader list?

    1. Anonymous says:

      I had the same problem. go to:
      CameraShape/mentalray/Lens shaders/create/legacy/physical_lens_dof.

  5. Froilan says:

    Very nice, ill deffinitely try this tonight, thanks for the tutorial :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s