Category Archives: Optimization

Global Illumination on the GPU

Get a sneak peak at the next GPU acceleration from nVidia for mental ray here (scene courtesy of Tai-Jen Su)

Notice in 9 minutes the GPU accelerated version is already complete while the non-GPU version has only completed the top left corner with similar settings.



MILA New Features – May

As the MILA shaders evolve, features will be updated here when possible. These shaders are inspired by the Material Description Language and you can find more on that from the GTC conference here: nVidia Material Definition Language for Coordinating Materials (Thanks to Saycon for the link in the comments)

This latest release includes some more user-inspired changes like:

  • A non-physical global clamp for reflection to eliminate hotspots (fireflies) from lights and interreflections
  • Independent direct and indirect contribution sliders on components to create non-physical but art driven look
  • Further moving of controls to global Quality String Options both for all MILA Quality as well as specific controls like “mila glossy quality” etc.
  • Continued work on the Quality controls adaptability meaning fewer tweaks, just set the shader look and hit render
  • Creating a Diffuse Reflection Detail Quality to replace Ambient Occlusion controls
  • Moving controls off the shader components to make them clean and easy, a move toward greater simplicity for mental ray (to be continued)
  • The elimination of unused or infrequently used controls
  • *experimental* propagation of additional buffers in secondary rays


The clamp option can be used as on or off (default is off) for controlling overbright highlights and reflections. It is a non-physical effect. This means it purposefully changes the energy in the render to avoid artifacts from insufficient sampling. This is usually caused by a very hot HDRI used to light a scene or a bright area light and the resulting indirect reflections.

This clamp option may also reduce render times because fewer samples are taken to resolve hotspots that cause variance in the image. The below image had an HDRI with a high value of over 7000 for the sun. Rendered at Quality 0.20 for Unified Sampling to amplify the effect of poor sampling. This also affects the resulting framebuffer contribution. Notice the areas that are not overly hot are maintained.

Clamp off and on

Clamp off and on

Direct and Indirect Contribution

A direct and indirect slider can be used to change the look of the material non-physically. Recall that Direct Reflection is the result of the light. Indirect Reflection is the result of the light from other objects in your scene. The easiest way to think of this is the direct diffuse is historically your diffuse pass and indirect diffuse is the indirect pass or “color bleed” from nearby objects reflecting light and measured by something like Final Gathering.

Below is an example with the effect of direct at 0.00 contribution and then indirect at 0.00 contribution on glossy reflection. You can adjust these independently to achieve a non-physical but pleasing artistic look in a material. This will also affect the resulting framebuffer contribution. These can be texture mapped as well for special effects.

Direct and Indirect scale comparison

Direct and Indirect scale comparison

Diffuse Indirect Detail

Diffuse Indirect Detail replaces the Ambient Occlusion controls with an On and Off switch globally, a distance parameter, and quality. Below is an example of on and off at default values.

Diffuse Detail on and off (animation)

Diffuse Detail on and off (animation)

Framebuffer Indirect Contribution Writing

*experimental* Additional buffers can now be rendered as seen in a reflection or refraction (indirect). This means you can get the matte color of an object written to its own buffer even if it is only seen in a reflected or transmitted ray. Below is an example where the turn blinker (indicator) writes its resulting color matte to the framebuffer despite being behind the lens cover of the light. It also contains information where it was reflected as well. This is useful to isolate and alter elements after rendering.

Headlamp with lens cover

Headlamp with lens cover

Amber Shader matte (color buffer) output

Amber Shader matte (color buffer) output

You can also pass the matte through another node like a rayswitch to further define the mattes generated through transmission (blue) or reflection (red) as seen below.

Amber material matte generated through a rayswitch

Amber material matte generated through a rayswitch

Now apply Glint!

Turn indicator with glint

Turn indicator with glint

Keep in mind that this object would be “baked” into the transmission framebuffer derived from the beauty. So changes after rendering would still be limited. This may also increase the render time as an extra color framebuffer is considered for anti-aliasing. If you wish to avoid that you can turn off “contrast all buffers” in the Quality Tab -> Framebuffer Rollout of your Render Settings.

Overall the goals for MILA are continued flexibility and simplicity based on MDL. Redundant and unused controls are moved and clarity in settings is being improved.

Why all of the “Quality” Controls?

Also notice the increase in controls for “Quality”. This is important since the underlying method or algorithm can be hidden under a simple control. This is already true of Unified Sampling and the Native IBL.

Why is this useful?

By hiding the method, developers can later change or improve it without introducing new controls or altering the old ones. This was true of the refinements made in Unified Sampling in 3.10. Artists can continue to work as the renderer improves without learning new techniques.

This is part of how mental ray will continue to simplify the workflow for users without sacrificing flexibility or speed. This will also make the integration of new features much easier in OEM products like Autodesk Maya since documentation and UI changes will be unnecessary with added improvements to existing features.

Shutter Efficiency – mental ray 3.11

Motion blur interface controls for "shutter shape function"

Motion blur interface controls for “shutter shape function”

Starting with 3.11, mental ray supports a shutter shape function ability for applying arbitrary exposure shapes to the shutter interval.  This allows for motion blur that better matches film.  While programmers can write their own functions, the built in trapezoid shape is good enough for most production needs.

Shutter Efficiency

Motion picture cameras use a rotary disc—a semicircular disk that spin in front of the film gate—as the shutter device.  Light is only captured when the missing part of the disk exposes the film gate.  This is referred to as the shutter interval.  The portion of the complete circle that the disk is missing is referred to as the shutter angle.  A shutter angle of 180˚ is considered normal for a motion picture camera.  A larger shutter angle results in a longer shutter interval and more motion blur effect.

A shutter that is completely open for the entire interval would capture the most light possible and would be said to be 100% efficient.  The physical nature of rotary disks means that the time it takes for shutters to fully open and close is non-zero.  This results in less light being captured at the ends of the shutter interval.  This softens the appearance of motion blur at its edges.

Shutter Shapes and Efficiency

Shutter Shapes and Efficiency

You can conceptualize shutter efficiency with a graph that plots exposure vs. shutter interval.  An idealized shutter would correspond to a box shaped function on this graph.  Real-world cameras have a more rounded shape that can be approximated as a trapazoid.  The minimum efficiency of a trapezoidal function is 50%.  Most real-world cameras are around 80% efficient.

Why do Maya cameras have a default shutter angle of 144˚ if 180˚ is more ‘correct’?

This is because renderers typically—and incorrectly—describe shutter exposure as being 100% efficient.  Using a shutter angle of 144˚ with a 100% efficient shutter matches the total exposure of a real-world camera.  That is:

144˚ × 100% = 180˚ × 80%

144° None (Box), 144° Trapezoidal Shutter @ 80%, 180° Trapezoidal Shutter @ 80%

144° None (Box), 144° Trapezoidal Shutter @ 80%, 180° Trapezoidal Shutter @ 80%

If you decide to apply an 80% efficient trapezoidal shutter shape to your scene, you may also want to adjust your render camera’s shutter angle to 180˚.  This will give you a similar result to the idealized case, except now with more physically accurate (and visually pleasing!) motion blur.

camera shutter angle

camera shutter angle

The Native (Builtin) IBL

Inside mental ray there is a Native or Builtin image based lighting scheme called environment lighting mode. This was integrated into mental ray some time ago in version 3.7. So it’s been around for about 4 years or more.

It’s unexposed in OEM packages but using our new UI for rendering, we have exposed it for use in Maya 2013. mentalCore also makes use of the Environment Light. We refer to the feature in the UI by its String Option name: Environment Lighting.

Edit: This is properly exposed in Maya 2015 in the Environment Lighting as “Light Emission”

Keep in mind you should be using the UI provided or at the least add the “light relative scale” string option to correctly light non-BSDF or legacy materials. Otherwise they will blow out. This is also true of the user_ibl_env shader. The MEL script below will add it otherwise. (This is unnecessary in Maya 2015 as it is already added from Autodesk.)

select miDefaultOptions; 
int $idx = `getAttr -size miDefaultOptions.stringOptions`; 
setAttr -type "string" miDefaultOptions.stringOptions[$idx].name "light relative scale"; 
setAttr -type "string" miDefaultOptions.stringOptions[$idx].value "0.318"; 
setAttr -type "string" miDefaultOptions.stringOptions[$idx].type "scalar";

Why do I want to use this?

Simply put: It’s fast and automatic direct lighting of scenes where your primary light source is a high dynamic range image (HDRI).

You have heard of this method in other packages as a Dome Light and in Maya 2013, the user_ibl_env was introduced with similar functionality.

Why would I use this instead of the user_ibl_env?

  • The Environment Light re-bakes data by point sampling an environment attached to your camera. This means it also accepts procedurals unlike the user_ibl_env shader.
  • In the baking process you can re-bake to a lower resolution that automatically blurs the texture detail, meaning typically faster glossiness and less variance
  • The Environment Light combines with BSDF shaders to use Multiple Importance Sampling automatically for quick renders
  • The Environment Light will allow you to continue to use the Maya IBL mechanism that is visible and manipulable from the viewport.
  • It uses a simple “Quality” scheme that is familiar from Unified Sampling and they work together accordingly.

Can’t I just light with Final Gather?

Sure. But Final Gathering (FG) samples in a way that distributes rays somewhat randomly. This means you have a few obvious problems illustrated below:

Rendering the scene with only Final Gathering as lighting

Rendering the scene with only Final Gathering as lighting

  • Splotches. Being an interpolated scheme means you need great accuracy to resolve fine lighting details.
  • Soft shadows and sort-of occlusion-like shadowing. You need a LOT of accuracy to get the shadows looking correct.
  • Complex or high contrast HDRIs need a lot of FG tuning.

An easy way to illustrate this is to look at the indirect diffuse lighting pass.

Indirect Diffuse pass without Builtin IBL

Indirect Diffuse pass without Environment Lighting IBL

Now try the Environment Light alone!

Environment Lighting Only

Environment Lighting Only

MUCH better with pretty much default settings.

Was it longer to render? Yes. It’s a brute force-like technique. But in order to get the same quality from FG would take much MUCH longer to render. So in that comparison, Environment Light is actually much faster.

What does FG + Environment Light look like?

Final Gathering with the Builtin IBL on

Final Gathering with the Environment Light on

In this situation I was able to capture direct and indirect lighting. But now, indirect lighting is only captured for object to object light reflection. Take a look at the indirect diffuse pass now (it’s very hard to see in this case, open in a new window):

Indirect diffuse lighting with Builtin IBL on

Indirect diffuse lighting with Builtin IBL on

This means you can greatly reduce your FG “accuracy” setting. In some cases as low as 8 or 16 rays. Keep in mind you might still need an FG filter setting of 1 if highlights on nearby objects are especially hot and generate speckles like the first indirect diffuse picture.

Another important thing when using the mia_material: by default it does not generate a specular (direct reflection) from a visible area light. This means your specular pass may be empty for the mia_material because it is using indirect reflection (reflection rays) to sample the environment. Other shaders that directly sample the Environment Light (like the car paint shader) may show noise or grain because it’s less efficient. To reduce this grain you have to increase the “Quality” of the Environment Light (or more Unified Sampling Quality at less efficiency)

Direct Reflection (specualr) is not generated for visible area lights like the Builtin IBL

Direct Reflection (specular) is not generated for visible area lights like the Builtin IBL

How can I set this up?

You can use the regular Maya procedure for adding an HDRI or a Texture to light the scene including the flags. You can also attach any environment to the camera such as an environment shader, environment switch or Sun & Sky.

Relevant controls built into Maya

Relevant controls built into Maya

What are the controls?

First: I want you to realize this is NOT the Maya IBL “emit light” option.

Do not use "Emit Light"

Do not use “Emit Light”

Here are the important exposed controls: (please excuse their existence in the Indirect Lighting Tab. It is a form of direct lighting as illustrated above.)

Environment Lighting Controls

Environment Lighting Controls

  • On: This means “Automatic” mode. Until the correct Progressive API is used in Maya, there is little point in using Approximate lighting mode. (Approximate generates probe rays and then fills in ambient lighting from the HDR for fast but inaccurate lighting. The other modes sample the light as a light source.)
  • Quality: Scalar slider for quality/grain control. Many scenes with sufficient texturing/complexity can get away with as little as 0.3. Increasing this value decreases grain/noise at the cost of speed, more shadow rays are traced. (Too much noise is insufficient Quality)
  • Scale: Multiplier for the light. Used to control tint/shade and brightness (value) The visible environment is not changed, only the light contribution. Environments are typically assumed to be comped later.
  • Shadow: Optimization, solid shadows are faster but treats all objects as opaque. Off is no shadows cast.


  • Cache: on/off, this creates an acceleration structure for faster lookup on complex lighting. This means the lighting lookup is done through a non-texture mechanism. Reflections may show artifacts at insufficient baking resolution (described below) but should light faster. Off = baked to texture with the usual implications/mechanisms for texture lookups.
  • Resolution: The lower the resolution, the faster the baking, less memory usage, and quicker rendering at the cost of details in reflection and lighting. (Works with iray as well) Below is an example where the resolution is so low the shadows are muddy and the lighting is very dim because the baking process missed some of the light sources. Below that is a correct version with higher resolution.
Rendered with low resolution samples (6 minutes a frame)

Rendered with low resolution samples creating muddy shadows and dark lighting (6 minutes)

Low resolution using Cache "on" (3.5 minutes)

Low resolution using Cache “on” (3.5 minutes)

More resolution to the lighting cache (4 minutes)

More resolution to the lighting cache (4 minutes)

Rendered with higher resolution to capture more lighting and details like multiple shadows

Rendered with higher resolution to capture more lighting and details like multiple shadows (5 minutes)

Resolution involving Cache “On”. Notice how the same resolution for the cache “on” mode did a better job by default for the lighting and shadows.

  • Shader Samples: When baking the IBL, this will take more samples before baking to avoid missing details or little hotspots. Useful with complex HDRI or small resolution settings like the above examples(Works with iray) This isn’t typically important with low contrast or low detail maps/procedurals. A ramp for example, will not benefit from more samples. Use this if you find that you are missing some small light sources or shadow details suffer. You can find a happy medium of lower resolution and some extra shader samples typically easily.
Cache "on" same resolution as above but more "shader samples". (Just over 4 minutes)

Cache “on” same resolution as the low settings above but more “shader samples”. Notice it resembles the high resolution version. (Just over 4 minutes)

Things to note:

  • HDRIs with low range or values will not produce crisp or deep shadows. You might want a happy medium range in a tonemapped HDR so you don’t have hot spikes in reflections and poor shadowing.
  • HDRIs with multiple light sources will automatically cast multiple shadows.
Automatic Multiple Shadows (Grace Cathedral EXR gain factor of 2)

Automatic Multiple Shadows (Grace Cathedral EXR gain factor of 2)

  • Don’t forget to use “light relative scale”!! (MEL at the top of the post)
  • Concave objects or interior scenes not lit directly by the Builtin IBL will need the usual higher quality FG and Portal Lights.
  • Set-acquired HDRIs work well for this with some additional bounce lights to “sweeten” the look.
  • The mip_matteshadow shader can be used to capture shadows for compositing onto live action plates.
  • Remember to use HDRI data. JPEGS and other common formats do not have enough range to produce good lighting.
  • Remember to reduce your Final Gather accuracy to speed up renders considerably. You do not need high settings since the Environment Light handles the bulk of the work.