Mental Ray Ambient Occlusion tutorial
Contents
Introduction
- What is Ambient Occlusion?
- Ambient Occlusion in Mental Ray
There are two main choices when using Ambient Occlusion: you can enable it as an effect in your shaders (using mia_material), or you can render a separate pass which you blend with your render in the compositing stage, using Photoshop for instance.
The benefit of the former is that the results will be more accurate and that you only need to make one scene-setup and render. The downside is that is difficult to 'tune' the effect. Re-rendering your entire image just to change the Ambient Occlusion effect may take quite some time. When using a separate AO-pass, it's quicker to tune your AO effect because rendering an OA-pass is typically pretty fast. Furthermore it allows more artistic freedom; you can fine-tune the AO effect during compositing (e.g.: in Photoshop).
Full Render with Final Gather and Ambient Occlusion
When using the mia_material, you can include Ambient Occlusion in your shader. This requires that you use the mia_material_x or mia_material_x shader. Although it's possible to add Ambient Occlusion to standard Maya shaders, this is quite laborious. If you're using non-mia shaders, it's recommended to render a separate AO-pass.
In the Hypershade select your material and check the properties box:
Locate the Ambient Occlusion section and open it. Enable Ambient Occlusion.
Distance
Change the Distance value:
The setting really depends on the size of your scene end the scale of the effect you're looking for. Just try different settings to get the right settings. You can render at low resolution to improve speed while doing this.
Samples
The quality is controlled by the number of samples. The default setting will produce pretty coarse results.
Increase the number of samples. 64 seems to be reasonable in most cases.
Rendering an Ambient Occlusion pass for compositing
Getting the amount of Ambient Occlusion just right may prove to be quite laborious. For maximum flexibility with low render times, it's a good idea to create a separate Ambient Occlusion pass that you can blend in during the compositing phase (for instance, using Photoshop).
To do this, you need to create a special shader that will just produce the Ambient Occlusion effect.
Creating a shader for the AO pass
We won't use any of the default shaders you normally work with, because they'll render other effects (such as diffuse or reflection components) as well. We're going to construct our own using a plain surface shader and an ambient_occlusion shader.
In the Hypershade, create a new Surface Shader:
Next, we need to create the Mental Ray mib_amb_occlusion node. Switch to Create mental ray Nodes to access the Mental Ray nodes.
Next connect the mib_amb_occlusion node to the surface shader by MMB draging it onto the surface shader1SG. Choose Surface Shader. The outValue should now be connected to the outColor of the surface shader.
Rendering the Ambient Occlusion pass
First, assign the surface shader to all objects in your scene.
Rendering an Ambient Occlusion pass is fairly simple: it doesn't require any light setup. So you can disable Global Illumination and Final Gather and remove all lights from your scene.
Tuning the Ambient Occlusion
You might want to tune the ambient occlusion shader you've created. First of all to to tune the distance of the occlusion effect. Secondly you may want improve the quality.
If your shader is not in Work Area of the Hypershade anymore, select the surface Shader in the Materials tab and click the Input and Output Connections in the toolbar:
Select the mib_amb_occlusion node in your Work Area. Check the Property Editor in the Hypershade.
Max_distance
Fine-tuning of the occlusion distance can be done in Photoshop (using Levels), but you may want to do some rough tuning in Maya.
Change the Max_distance value:
The setting really depends on the size of your scene end the scale of the effect you're looking for. Just try different settings to get the right settings. You can render at low resolution to improve speed while doing this.
Samples
The quality is controlled by the number of samples. The default setting will produce pretty coarse results.
Increase the number of samples. 128 seems to be reasonable in most cases.
Render Settings for the AO-pass render
We're going to use the render as a layer in Photoshop. Therefore we don't want the background included. When using an alpha channel, you may get some artefacts at the edge between the objects and the background. To get a clean alpha mask, we need to change a few settings in the render settings:
- Disable premultiply under Framebuffer > Primary Framebuffer
- Enable Pass Custom Alpha Channel under Custom Entities
This will disable 'blending' the background with the objects in the anti-aliasing phase, keeping your edges clean.
To improve quality, you may want to increase your Anti-Aliasing settings. Example settings are given in the image below:
Once you're satisfied with the result, save your image as PSD. Alternatively you can use TIFF, but than you have to load your alpha channel manually in Photoshop.
Compositing the AO pass with your image in Photoshop
You should have two images:
- The render with color information (also called color-pass). Preferably in TIFF format
- An image with the Ambient Occlusion pass (AO-pass). Preferably in PSD format (or TIFF)
Open both images in Photoshop. Drag the layer from the AO-pass (from the Layers panel) to the color-pass image and position it. You can rename the layer to something more useful (eg: 'AO-pass').
Next we have to blend this layer with the color-pass:
- Select the layer with the AO-pass.
- Open the Blend-mode pull-down in the layers panel.
- Choose Multiply. Alternatively you could choose Darken; the effect will be more subtle.
You can tune the effect by changing the Opacity of the AO-pass layer.
You can also change the levels of the AO-pass layer using an adjustment layer:
- Select the layer with the AO-pass.
- Alt + LMB-click the 'Create Adjustment Layer' button at the bottom of your layers panel: (keep you mouse button down)
- Choose Levels...
- In the popup, check Use previous Layer to create Clipping Mask. This will create a mask so the Levels will only applied to that part of the image where there is color in the AO-pass (effectively keeping the background unaffected). Close with OK.
- You can tune the AO-pass using levels to get the desired effect.
The final result of the image used in this tutorial: