Monday, August 27, 2012

RenderHelper - Maya Mental Ray render utilities


This is a collection of Mental Ray for Maya utilities.  I found myself repeating the same Mental Ray setup steps or building the same node graphs so many times I made small convenience shelf buttons.  The number of buttons grew so I collected them all into a single UI.

This should work in Maya2012+, at least it does for me...

How to Set Up RenderHelper
  • Download
  • Unzip.
  • Copy all files to wherever it is you save MEL scripts.
  • Copy the code snippet to the ScriptEditor .
  • Highlight all of the code snippet in The ScriptEditor.
  • Drag and Drop it onto a shelf.

source "/path/to/maya/code/RenderHelper/RenderHelperMenu.mel";
source "/path/to/maya/code/RenderHelper/AASettings.mel";
source "/path/to/maya/code/RenderHelper/GammaSettings.mel";
source "/path/to/maya/code/RenderHelper/MentalRayLoad.mel";
source "/path/to/maya/code/RenderHelper/MentalRaySettings.mel";
source "/path/to/maya/code/RenderHelper/MentalRayTextureSettings.mel";


Thumbnail Update
Have you ever had Hypershade slow to a crawl, where changing one attribute would cause a 5 minute wait?  If "yes", then the most likely culprit is the shader swatch ( aka. thumbnail ).  Maya is recalculating your node graph, and it's taking way longer than if you had just rendered the entire scene at full resolution.  If you are using a linear workflow the swatch color is completely irrelevant anyway.

Thumbs ON = All swatches update
Thumbs OFF = No swatches update ( my personal preference )

Image Format
These are the three image formats I use for all of my renders.  It also sets the bit depth depending on the image type, the format to name.#.ext and the frame padding to 4.  These are standard settings for SPA.

jpg = sets the render to 8bit jpegs
tif = sets the render to 8bit tiffs with alpha
exr = set the render to 32bit exrs with alpha

All based on HD 1920x1080 which is our most common image size.

HD = 1920x1080 aspect ratio 1.778
Half HD = 960x540 aspect ratio 1.778
Quarter HD = 480x720 aspect ratio 1.778

Anti-Alias Settings
These are more of a rough guideline than rule as each image requires different settings.  Mostly I use it as a way to lower the AA settings to do quick render tests.

AA low =  min -2 max 0 contrast 0.5
AA ned =  min -1 max 1 contrast 0.25
AA hi    =  min 0  max 2 contrast 0.1

Add Camera Lens
I like to use a lens shader with Mental Ray.  It gives me some flexibility with the image before it goes to comp.  The buttons work with cameras that you have selected, or if none are selected, it works with all cameras in the scene.  Any button in this menu that deals with Mental Ray will automatically load Mental Ray and make it the current renderer.

Simple = mia_exposure_simple
Photographic = mia_exposure_photographic

Add MR Lights
Standard Maya lights with Mental Ray light shaders.  Some Mental Ray specific attributes are turned on in the light shapes node.  The color is controlled by a blackbody.

Area Portal = Area light with a mia_portal_light shader.
Area Photo = Area light with a mia_photometric shader.
Spot = Spotlight with a a mia_photometric shader.
Point = Point light with a a mia_photometric shader.

Mental Ray Texture Settings
When you create a sub-surface scattering shader, Maya will automatically create all the necessary nodes and connect them.  This is a great time saver.

Two of the nodes created are a mentalrayTexture and an expression. The MR texture's job is to hold the result of the sss calculation that happens at the start of a render.  The file size needs to be 2x the width of your current resolution because the calculation contains the front and back of what you see through the camera, the front and back are interlaced.  The expression's job is to set the resolution of the MR texture based on your current resolution set in Render Globals.

This works out well until you want to generate quick renders.  Sometimes the calculation of the sss can take a while.  You can get around that if you save the result and hard-code it to the texture, but if you change the camera, camera angle or position of the geo, you have to recalculate the sss.

To work around this, I add a "file_mult" attribute to the MR texture, and replace the existing expression.  If you want to generate a sss map quickly, at the cost of quality, you set the "file_mult" attribute to a low value.  It acts as a multiplier to the resolution.  So a value of 0.5 will render a sss map half res.  You could also set the value above 1 and generate an even higher res if you wish.

MR tex low = file_mult 0.25.
MR tex med = file_mult 0.5.
MR tex hi = file mult 1.0.

The other buttons in the section are selection routines.  They should be self-explanatory since the description of what they do is on the button.

Mental Ray Verbosity
This controls how much information Mental Ray prints out about your render.  They are numbered 1 through 6 and directly relates to the Mental Ray values.

Gamma Nodes
The rest of the buttons create, insert, set or rename gamma nodes.  Gamma nodes are used in a linear color workflow.

New Gamma Node
Just makes a gamma node with different values.  No connections are made.

New Gamma .455 = Creates a gamma node with a value of .45454545...
New Gamma 1.0   = Creates a gamma node with a value of 1.0.

Insert a Gamma Node ( I see I have a typo in the UI.  I'll fix it in the next release. )
Create a gamma node and connect it between a texture node and its output, namely outColor.  Let's say you have a file texture node connected to the diffuse channel of a Lambert shader.  If you select the file texture node and click [Ins Gamma .455], it will place a gamma node between the file texture node and the diffuse channel.

Ins Gamma .455 = Places a gamma node with the value .45454545... between two nodes
Ins Gamma 1.0   = Places a gamma node with the value 1.0 between two nodes

Set All Gamma Nodes
Sets the value on all gamma nodes to the specified value.

Set Gamma .455 = Sets all gamma nodes to .45454545...
Set Gamma 1.0   = Sets all gamma nodes to1.0

New Ramp with Gamma
Creates ramp, gamma and place2dTexture nodes, then connects them.  I use a ramp with a single color connected through a gamma node if I need just a single color for a shader.  That way I can know the what the color will look like in a render.

Ramp Gamma .455 = Create a ramp with a gamma node set to .45454545...
Ramp Gamma 1.0   = Create a ramp with a gamma node set to1.0

New File with Gamma
Creates file, gamma and place2dTexture nodes, then connects them.

File Gamma .455 = Create a file texture with a gamma node set to .45454545...
File Gamma 1.0   = Create a file texture with a gamma node set to1.0

Rename Nodes
When you create any node in Maya but do not specify a name, Maya names it for you.  Normally the name is nodeType#.  In the case of gamma nodes, it names them gammaCorrect#.

This is normally not an issue, but if you are in a large studio where all names matter, you need to name the node based on your pipeline requirements.  For SPA that name is <input node>_gamma.  So if we made a file texture node and call it eye_diffuse_col_file, the connected gamma node should be named eye_diffuse_col_file_gamma.

Rename Gamma = If you select a gamma node and hit the button, only that node will be renamed.  If you have no nodes selected, it renames all gamma nodes.


  1. It doesn't function! It's possible to know if I can change the path of the script? When I try to load the script an error message appear.

    // Error: Cannot find procedure "spInclude". //

    It's possible to know step by step how to load it into maya?

    Thanks in advance

  2. hi thare
    got this error:
    // Error: Line 6.70: Cannot find file "/path/to/maya/code/RenderHelper/MentalRayTextureSettings.mel" for source statement.
    how can i load't?