Monthly Archives: October 2011

Unified Sampling

“Driller” from Transfromers 3: Dark of the Moon – rendered with unified sampling

For the layman, unified sampling is a new sampling pattern for mental ray which is much smarter than the older Anti-Aliasing (AA) sampling grid.  Unified is smarter because it will only take samples when and where it needs to.  This means less wasted sampling (especially with things like motion blur), faster render times, and an improved ability resolve fine details.

Technically speaking, unified is Quasi-Monte Carlo (QMC) sampling across both image space and time.  Sampling is stratified based on QMC patterns and internal error estimations (not just color contrast) that are calculated between both individual samples and pixels as a whole.  This allows unified to find and adaptively sample detail on a scale smaller than a pixel.

Advantages of unified sampling:

  • Fast ray traced motion blur.  Also motion blur should be smoother and require less memory.
  • Fast ray traced depth of field.
  • Better at picking up small geometry and detail.
  • A foundation for future rendering techniques and materials.

You SHOULD use unified sampling.  Here is how…

How to Enable Unified Sampling (Prior to Maya 2014 without the Community UI)

Unified sampling is not exposed within Maya but can be enabled and with string options.

Enabling unified sampling

“unified sampling”

  • Enables or disables unified sampling.
  • boolean, defaults to false

Note: You should use “Raytracing” with regular and progressive unified, NOT the default of “Scanline” (Render Settings > Features > Primary Renderer).  This is because the scanline mode is old, deprecated, and none of the cool kids are using it.  Switching to raytracing from scanline can take minutes off your render while reducing memory usage.  Using “Rasterizer” with unified sampling enables the unified rasterizer.

Unified Controls

In addition to performance improvements, unified sampling simplifies the user experience by unifying the controls for various mental ray features including progressive rendering, iray, and even the rasterizer.  For regular unified and progressive unified, you basically just have one control that you need to consider: Quality.

“samples quality”

  • This is the slider to control image quality.  Increasing quality makes things look better but take longer.
  • It does this by adaptively increasing the sampling in regions of greater error (as determined by the internal error estimations mentioned before).
  • You can think of quality as a samples per error setting.
  • Render time increases logarithmically with “samples quality”.
  • Generally leave it somewhere between 0.5 (for fast preview) and 1.5.  1.0 is deemed “production quality”.  You can go higher (or lower) if the situations demands it.  Possibly values are 0.0 and above.
  • scalar, defaults to 1.0

Additional Controls

“samples min”

  • The minimum number of samples taken per pixel.
  • Set to 1.0.  Don’t change this unless you have a pretty gosh darn good reason.
  • Using a value less than 1.0 will allow undersampling.  This could be useful for fast previews.
  • This is only a limit.  Use “samples quality” to control image quality.
  • scalar, defaults to 1.0

“samples max”

  • A limit for the maximum number of samples taken per pixel.
  • The default setting of 100.0 will generally provide you with a large enough range of adaptivity for production work.  Some situations, such as extreme motion blur or depth of field, may require more than a hundred samples per pixel to reach the desired quality and to reduce unwanted noise.  Setting “samples max” to 200.0 or 300.0 in these situations can help.
  • This is only a limit.  Use “samples quality” to control image quality.
  • scalar, defaults to 100.0

“samples error cutoff”

  • Provides an error threshold for pixels that, when error falls below this value, mental ray will no longer consider.
  • This is only useful for scenes with very high quality values (like 3.0+) where areas of low error are still being sampled/considered.
  • In general, use “samples quality” as the sole method to control image quality and leave “samples error cutoff” at 0.0 (disabled).
  • If you choose to use this setting, set it to a very low value like 0.001.
  • scalar, defaults to 0.0

“samples per object”

  • Allows you to override “samples min” and “samples max” on the per object level.
  • If enabled, overrides are set under the mental ray section of each object’s shape node.
    • “Anti-aliasin Sampling Override” is the override switch
    • “Min Sample Level” sets “samples min”
    • “Max Sample Level” sets “samples max”
    • Note: these values have different meanings for unified sampling than they do for AA sampling.  i.e. a value of 3 corresponds to 3 samples per pixel, not 2^(3*2) = 32
  • boolean, defaults to false

You can learn more about using Unified Sampling in the Unified Sampling for the Artist post.

Additional Notes

When unified sampling is enabled, mental ray will ignore certain settings:

  • The AA settings (ie min sample level, max sample level, anti-aliasing contrast) are ignored because you are now using the new unified sampling pattern.
  • Jitter is ignored because unified is inherently QMC jittered across image space.
  • With motion blur enabled, time samples/time contrast (these are the same setting) is ignored because unified is also QMC jittered across time.  You still need to set motion steps for motion blur.

Quality and error cutoff can be set to per color values for RGB. This is probably overkill for 99% of situations.  If you wish to control per color values, you can adjust the string options to look something like this:

  • “samples quality”, “1.0 1.0 1.0”, “color”
  • “samples error cutoff”, “0.0 0.0 0.0”, “color”


String Options

String options are currently Autodesk’s main method for integrating new mental ray features.  While very few people would say they “like” using string options, you don’t really have a choice if you want to use anything new in mental ray.

What are string options?

String Options are essential a tool for you to declare a variable to the mental ray renderer that is not directly built into the Maya/mentalray translator.  You can use string options to tell mental ray to turn on/off a feature and what settings to use.

You can read more about possible string options in the mental ray documentation that comes with Maya.

Where do string options hide?

The miDefaultOptions node

String options are located on the miDefaultOptions node.  There are several ways to get to the this node.  I generally use this MEL command:

select miDefaultOptions;

If you are currently screaming with horror, you should consider creating a custom button on the shelf editor with this command.  You can also select miDefaultOptions from the outliner if you have don’t have “Dag Objects Only” checked (Outliner > Display > DAG Objects Only).  Fun stuff.

If you get a “No object matches name: miDefaultOptions” error, make sure that the mental ray plugin has been loaded and that the default mental ray nodes have been created (if they have not been created, setting the renderer to mental ray in render settings should do the trick).

How to set string options

To create a new string options, click “Add New Item”.  For each string option that you create, you need to know three things: Name, Value, and Type.

Name: The name of the mental ray setting which you are adjusting.  If you don’t know this you don’t know anything.  Make sure you spell the name correctly or mental ray will ignore the setting.

Value: The value that you wish to give that setting.  Values must be of the correct Type.

Type: The data type of the specific setting:

  • “boolean” – The most basic data type representing True or False.
    • Possible Values: “true” or “false”, “on” or “off”, 1 or 0, etc.
  • “integer” – A whole number.
    • Possible Values: -2, 0, 45, 23053, etc.
  • “scalar” – A decimal number.
    • Possible Values: -23.567, 0.0, 0.00005, 3.14159, 1000000000000000000000.0, etc.
  • “string” – Any text.
    • Possible Values: “hello world”, “automatic”, “off”, “0.0”, etc.
  • “color” – A color usually represented by 3 scalars for RGB.
    • Possible Values: 1.0 1.0 1.0. (for white), 0.0 0.0 0.0 (for black), 0.5 0.234 0.0, etc.

Note: mental ray will also recognize “bool” for “boolean”, “float” for “scalar”, “int” for “integer”, or “vector” for “color”.