Mental Ray Ambient Occlusion tutorial

From TOI-Pedia

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 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.

Not that you need to enable either Global Illumination or Final Gather (or both) to work with the mia material.

Open the attributes of the mia_material:

Mia material amb occlusion.jpg

Locate the Ambient Occlusion section and open it. Enable Ambient Occlusion.

Distance

Ambient Occlusion render with max_distance 8
Ambient Occlusion render with max_distance 2

Change the Distance value:

Mia material ao distance.jpg

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

Ambient Occlusion render with 16 samples
Ambient Occlusion render with 128 samples

The quality is controlled by the number of samples. The default setting will produce pretty coarse results.

Mia material ao samples.jpg

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:

Hypershade new surface shader.jpg

Next, we need to create the Mental Ray mib_amb_occlusion node. Switch to Create mental ray Nodes to access the Mental Ray nodes.

Hypershade new mr ao shader.jpg

Next connect the mib_amb_occlusion node to the surface shader by MMB draging it onto the surface shader. Choose Default connection. The outValue should now be connected to the outColor of the surface shader.

Amb occl surface shader.jpg


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:

Hypershade show input output connections.jpg


Select the mib_amb_occlusion node in your Work Area. Open the Attribute Editor (Ctrl + a).

Mib amb occlusion attributes.jpg


Max_distance

Ambient Occlusion render with max_distance 0 (auto)
Ambient Occlusion render with max_distance 8
Ambient Occlusion render with max_distance 2


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:

Mib amb occlusion maxdistance attribute.jpg

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.

If you render an interior scene increase your Max Distance. This way you prevent getting a dark render

Samples

Ambient Occlusion render with 16 samples
Ambient Occlusion render with 128 samples

The quality is controlled by the number of samples. The default setting will produce pretty coarse results.

Mib amb occlusion samples attribute.jpg

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 artifacts 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:

Rendersettings mr alpha channel.jpg

  • 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:

Rendersettings mr aa for ao.jpg


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)

Photoshop color-pass.jpg Photoshop ao-pass.jpg

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.

Amb occl tutorial layers multiply.jpg


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: Photoshop add adjustment layer.jpg (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.

Amb occl tutorial layers with levels.jpg


The final result of the image used in this tutorial:

Final result - composited from the Color- and the AO-pass
Personal tools
Actions
Navigation
Tools