One-Click Ambient Occlusion in Maya

Here’s a quick script that will take any scene and give you an ambient occlusion render all in one step. The script requires either Maya 2014 or greater (since it uses the turtle plugin) or the turtle plugin installed to the default directory. Simply run the script and you should see an ambient occlusion render pop up! You should be set up with decent default settings, but if you want to tweak the render further, head into the Turtle render settings and the ambientOcclusion_mtl and tweak all you want.

import pymel.core as pm
import maya.mel as mel

# Settings
layerName = 'AO_layer'
mtlName = 'ambientOcclusion_mtl'
shaderName = 'ambientOcclusion_shader'

# Load the Turtle plugin, set basic settings
pm.loadPlugin( 'Turtle.mll' )
mel.eval( 'setCurrentRenderer turtle;' )

# This line ensures that turtle had time to fully load
pm.general.setAttr('TurtleRenderOptions.renderer', 0)
pm.general.setAttr('TurtleRenderOptions.aaMinSampleRate', 0)
pm.general.setAttr('TurtleRenderOptions.aaMaxSampleRate', 4)

# Only create the ambient occlusion shader if it doesn't already exist
if not shaderName in'shadingEngine'):
    AO_mtl = pm.rendering.shadingNode("ilrOccSampler", asShader=True, name=mtlName)
    AO_shader = pm.general.sets( renderable=True, noSurfaceShader=True, empty=True, name=shaderName )
    AO_mtl.outColor >> AO_shader.surfaceShader

# Only create the AO render layer if it doesn't already exist
if not layerName in'renderLayer'):
    pm.createRenderLayer(n=layerName, mc=True, g=True)
    pm.editRenderLayerGlobals( crl=layerName )

# Assign the AO_shader to everything

# Turn off default render layer
mel.eval('renderLayerEditorRenderable RenderLayerTab "defaultRenderLayer" "0";')

# Render

Leave a Reply

Your email address will not be published. Required fields are marked *