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.