The following tutorial shows how to use lens shaders with mental ray for maya. You'll need the mental ray for maya plugin and you have to activate the custom mental ray nodes. You can do this by activating the environment variable "MAYA_MRFM_SHOW_CUSTOM_SHADER" with an value of of 1. If you're using Windows, go to System Control / System / Advanced / Environment Variable and create a new variable called "MAYA_MRFM_SHOW_CUSTOM_SHADER" and set the value to 1.
First create a line of objects and a camera so you can test the depth of field (DOF) effect. You can use this link to download a sample file. Load the mental ray for maya plugin if you have not already.
The easiest way of doing DOF is using the default maya method and just use mental ray instead to render the image. To activate DOF just select the camera and open the attribute editor. Go down a little bit in the shape node to Depth of Field and activate it.
To get better control over the focus settings, we will use the measure tool to compute the distance between two locator objects. Use "Create / Measure Tools / Distance Tool" and select the camera and one of the objects. Activate the selection handles on all objects and the camera, this way you can use point select when creating the measure tool!
Now you could just take the displayed value and enter it manually. To automate it, we'll use the connection editor and connect the "Distance" attribute with the "Focus Distance" attribute in the camera shape. Use the connection editor to do this. The easiest way is to load both objects in the hypergraph and drag and drop the distanceDimension shape node over the camera shape and use other in displayed menu. Now the connection editor automatically loads the distance shape node on the left side and the camera shape on the right side. Select the "Distance" attribute on the left side (should be the last) and the "Focus Distance" attribute on the right side (scroll a little bit down to find it).
Now re-render it. Try changing the "F Stop" and the "Focus Region Scale" attribute. Also try to change the position of the locator. Use the second object for the distance locator (around 88 units) and a focus region scale of 0.1.
Let's see how a Lens Shader setup works. Deactivate the maya based "Depth of Field" from the last step. Open the camera in your attribute editor, navigate down to mental ray and use the checker board next to "Lens Shader" to open the "Create Render Node” dialogue. Select "Physical Lens DOF". If you can't find this rollout in the camera shape, than you'll have to activate the custom nodes as described at the top!
You could create this node with the following MEL command and connect it manually:
mrCreateCustomNode -asUtility "" physical_lens_dof;
Deactivate the maya based "Depth of Field" we used before. If you wanna play with the lens shader a little bit, than you have to use negative values for the distance (plane)! Because we wanna use the distance tool to control the Plane attribute, we'll connect the distance with an reverse node and than connect this to the Plane attribute.
Create an reverse node with the following command:
shadingNode -asUtility reverse;
Now shift-select the camera and load this selection into the hypergraph. Now drag and drop the distance node over the reverse node and use other to open the connection editor. Use the distance attribute at the end of the distance shape node attribute list and Input / Input X on the right side (reverse node).
Now drag and drop the reverse node over the lens shader and use again other to open the connection editor. use Output / Output X on the left side and Plane on the right side. Play with the Radius attribute to change the effect.
One thing you should have in mind is, that the sampling values needs to be upped. That's the only bad thing on this. But you can set-up an post-blur effect with distance dependents in mental ray too...
If you have more questions, just use your email editor email@example.com...