Blog Archives

Object Lights – mental ray 3.11 *small update*

**UPDATE** Maya 2016 makes these lights an integrated option using the create menu.

Create Lights menu Maya 2016

Create Lights menu Maya 2016


**Maya 2015 SP3 delivers the builtin_object_light shader and works correctly/stably with mental ray 3.12 Be sure and follow the other tips like turning off the shading engine until integration is done.**

One of the most requested features for mental ray has been an object, or mesh, light. This is a somewhat experimental feature since it’s not exposed it was not tested in the Maya Betas. *There has been some talk of crashes, but sporadic. The cause has been found and is up for a fix now in mental ray, thanks for the extra reports to find it. Also, be sure and select not to Export with the Shading Engine in the Shading Group node to avoid the naming emission irregularity.*

Lighting a space using Final Gather from self-illuminated objects can be tedious to tune and costly in render times. Typically you need large amounts of rays (accuracy) from Final Gather to achieve smooth lighting this way. You can see such an example below with accuracy set to 1024.

Lighting using Final Father

Lighting using Final Father

An object light is the ability to define a shape as a light source. This allows greater flexibility in lighting scenes where a physical object is better (like a neon tube sign) or more efficient for rendering than an emissive plane with Final Gather.

The ability to make an object into a light has been available in mental ray for a long time and in an .mi file it’s a simple line that tells the renderer that the object is a light.

mental ray also supports geometric area light sources for point lights, specified by the object keyword. Its first argument must be the instance of a single-group object that defines the geometry of the area light source. All points on the surface of the object will emit light uniformly. It is generally a good idea to keep the triangle count of the object as low as possible for maximum performance. The sampling rates usually have to be set much higher for object lights.

If you look at the .mel for the area light AEtemplates in Maya, you’ll see legacy code where this was accomplished at some point in the past but disabled. The usual reasoning is that object lights can generate a lot of noise in a render that is difficult to clean up.

However, since the inclusion of Unified Sampling, you’ll see that cleaning up area light noise is much easier with fewer samples than before. This makes for a faster render that’s easier to control.

mental ray 3.11 includes a new shader called the builtin_object_light that tells mental ray that the object is a light. This circumvents anything that might be required by integration to work.

There is no library file that is needed for this shader, e.g. .dll, .so etc. Since it is “builtin” you just need the .mi declaration saved in the include folder for the mental ray plug-in. You can copy the code below and save the file. Keep in mind you should save these scenes as .ma if you wish to maximize compatibility since there are no node IDs for this shader.

    declare shader
       color "builtin_object_light" (
       color "surface" default 1 1 1 1,
       light "light"
       )
       version 1
       apply material, photon
    end declare

I saved it in Windows here: C:\Program Files\Autodesk\mentalrayForMaya2014\shaders\include

Opening Maya (being sure it’s loaded under the Shader Manager).

Shader Manager

Shader Manager

You can now see the simple UI below.

Builtin Object Light

Builtin Object Light

The simple workflow is:

Assign builtin_object_light material to Object -> create area light -> attach area light .message to Light parameter of builtin_object_light shader. (This picture needs updated below, you should attach the transform, not the shape)

Area Light connected to the Object Light Shader

Area Light connected to the Object Light Shader

Render.

Object Light, no FInal Gather

Object Light, no Final Gather

You will notice that the object light still follows the shape node rendering flags like cast and receive shadows. That’s why there is a ring shadow around the box. This is not particularly intuitive so you can turn off cast and receive shadows and render again.

Control certain attributes through the Shape node

Control certain attributes through the Shape node

Cast and Receive Shadows Off

Cast and Receive Shadows Off

For these examples I have the “visible” parameter of the Area Light On. This means the object light primary ‘look’ is controlled through the “shape intensity” of the Area Light and the light shader. If this option is off, the look is controlled through the builtin_object_light “surface” control.

I actually recommend you leave that parameter On when possible. Having the Area Light Visible set to “Off” causes direct reflection sampling of the light even if the object is still visible. Instead you should use the Shape Node Render Stats to control the visibility of the light like you would any object in the scene.

Below I have the walls of the box semi-reflective and moved the light so that it’s more obvious when it’s hidden.

Box with reflective sides

Box with reflective sides

Now I will turn off the primary visibility on the Shape Node as seen below.

Primary Visibility Off

Primary Visibility Off

Here is the resulting render:

Primary Visibility Off

Primary Visibility Off

So now you can control how the light is sampled and seen in your image.

Also notice that light shaders applied to the area light will work as well but may have unintuitive consequences. In some cases light quadratic falloff of the visible light and not just the light effect itself is noticed. This means as the light is scaled or moved into the distance, it will change primary intensity (its lighting effect remains the same).

Being creative with node networks will also allow you to do things like cutouts and transparency on a light as seen below. The light in the scene is a solid plane with a checkerboard attached as illumination as well as connected to a mib_continue to allow rays to pass through. The alpha of the light is also controlled in the same way. The box is left slightly reflective as above to show the reflection of the checkerboard on the back wall.

Checkerboard Procedural along with alpha transparency.

Checkerboard Procedural along with alpha transparency.

These options will also combine with the new Light Importance Sampling found in 3.11 for textured lights.

Light Importance Sampling (light IS)

Light Importance Sampling in mental ray 3.11 will allow mental ray to distribute samples more effectively on textured area lights.

Why would I use Light IS?

This means samples are more efficient when lighting a scene where you may have textured object lights or bounce cards using an HDRI as the light source. This is similar to the user_ibl shaders but is now a core feature, potentially applying to more light types in your scene through a global option. In this way, once it is integrated it will deprecate the user_ibl shaders.

You can find more about this in the release notes and enable them in Maya using String Options. Below is an example from the documentation of settings:

The String Option: “light importance sampling” has three settings.

  • off or "off", default. Importance sampling is not applied.
  • on or "on". Importance sampling is enabled for rectangular and disc area lights with high emission variance, and for all spherical, cylindrical and object lights. This mode is useful for rectangular and disk light with uniform intensity. In this case the core will check to see if the light emission has sufficient variance (between light and dark) to justify light importance sampling (Light IS). Non-planar lights (like an object light for example) always compute for light IS. This also applies to planes being used as Object Lights despite being similar to a rectangular light. This means it is sampled for Light IS but may not make a difference in render quality if not textured.
  • "always". In addition to “on”, importance sampling is enabled on all rectangle and disk lights. This mode means Light IS is used even if the variance of the light emission is low and might be ignored otherwise. (An additional variance option exists if you want to tweak what is considered to be enough variance to trigger light IS)

There is also “light importance sampling precomp” string option with values of on or off. This option presamples lights (there’s some overhead before rendering) for lights with HDRI attached to them. This can reduce the variance (noise) in a final image. Take note your image might look slightly different with this option on. This option is a compliment to the settings above as it changes how the lights are sampled during the render but not required. Recommended if a lot of your lights are using HDRI or high variance textures.

All of the modes will present log output telling you if the lights you have are being considered for Light IS. If there is more overhead for sampling but your log tells you the lights aren’t using Light IS (not textured or not enough variance) then you might switch it off and render normally.

Take care that since the mayastate shader has not been updated to be aware of this option it will generate a long warning log with “unexpected ray” readouts.

This is a feature that will have more explanation at a later time since it is more involved.

The user_ibl shaders: Part 1

Introduced with mental ray 3.10 are new shaders called the user_ibl shaders.

Inside this shader package are two new shaders with different usage scenarios.

  • user_ibl_env
    • A more simplified usage than the Native IBL (mental ray), the user_ibl is a scene entity used for lighting a scene globally from an environment.
  • user_ibl_rect
    • A shader used to generate light cards or “billboards” to replace otherwise complex geometry and lights in a scene. An example workflow is discussed with Speed Racer and Digital Domain: How to Paint a Digital Car 

Part 1: The user_ibl_env

Why would you use this instead of the Native IBL with string options?

The user_ibl_env can be used as a shader in the scene. This means it can be operated and manipulated as a scene shader attached to an area light. It also improves on the importance sampling used by the Native IBL.

The shader uses a connection to a texture. This means it has direct access to all of the detail found in an HDR image. The Native IBL will bake anything (including procedurals) attached as an environment. The user_ibl_env requires a texture to work correctly. If you are using a procedural like a ramp, it should be baked to a 32-bit image format like an HDR or EXR for rendering.

A model car rendered with user_ibl_env and HDR

First, let’s look at the shader settings:

user_ibl_env Shader Settings

Texture: This is where you attach a lat-long formatted HDR or similar high dynamic range texture to be used to light the scene.

Samples: The samples used for lighting. This is the maximum number of samples used for lighting. More complex images or images with wide ranges of values may need more samples. As the importance of the sample becomes less (maybe it’s a few reflections or refractions later) the shader may call fewer than this number.

Color: A scaling factor (RGB) for the colors in the texture. You can use this to manipulate the texture colors from the shader.

Intensity: A standard multiplier for the lighting effect. 2 = twice a s bright. 3 = three times as bright, etc.

Shadow Mode: 0 = opaque 1= solid 2 = transparent  The default is transparent shadows (good for images with windows or colored glass). The UI can be changed by using the enum attribute in the .mi file that will give you a dropdown menu instead of an integer field. Change the line in the .mi file regarding the shadows to this:

integer "shadow_mode" default 2,            #: enum "no shadow:opaque:transparent"

Added “enum” attribute to the .mi file.

Rotate: This rotates the lat-long texture for placement. This is measured in degrees.

As Reflection: Was the image being used for lighting shot through a reflection (mirror ball)? This will reverse the image to correctly integrate objects.

Primary: Visibility

How do you use this shader correctly?

There are some steps to correctly use this shader inside Maya. We’ll look at them here step by step.

1. Create an area light in Maya. Its position and size do not matter. Under the mental ray rollout select Use Light Shape.

2. Under the mental ray ->area light rollout,  Set the area light to ‘visible’.

3. Set the Type to Custom

4. Under the mental ray -> Custom Shaders attach a user_ibl_env shader to the Light Shader connection

5. To keep things easy, use the Maya Connection Editor to connect the user_ibl_env Samples to the High and Low Samples of the Area Light

Connect the user_ibl_env samples to the area light samples

A final area light:

A connected area light set up for the user_ibl_env

If you try to render your scene now, it won’t light as an environment. You still need to attach this shader to the Environment connection on the camera under the mental ray rollout.

Attach the user_ibl_env to the camera Environment

Additional Notes on this connection: You can still use ray switches and the mia_envblur shader here and attach the user_ibl_env to them. Keep in mind you may need to use a large resolution setting in the mia_envblur shader to preserve detail in reflections.

Lastly, and very important: you must use the string option for Light Relative Scale for this shader to correctly scale the light for non-BSDF or older (legacy) shaders. This value is 1/pi. This is added in the miDefaultOptions.

Name: light relative scale

Type: scalar

Value: 0.318

Now render with Unified Sampling. The following image was rendered using a backplate and HDR from: HDR Labs.

user_ibl_env example render

 

Additional Notes:

  • In these images I did not use indirect lighting. If you do use it in such a scene, you can decrease the quality by quite a lot. Maybe 16 or 32 rays (or around there) for Final Gather.
  • Insufficient samples for the user_ibl will show as grain in the image. In motion, slight grain won’t be noticed, don’t over-tune your scene.
  • Avoid using any shader where it forces a specular (direct reflection) calculation from these lights. It will cause noise and increase render time.
  • Do not defeat the importance sampling mechanism by making the High and Low Samples of the area light different than the user_ibl shader. Let it do the work for you.

Area Lights 101

As computers and algorithms become faster and smarter, area lights can be used more often without much performance penalty.

Why would you use an area light?

In the real world, lights of all types are represented in 3-dimensional space, meaning all lights have area from which they emit light.

A tungsten light bulb has a tiny filament, the tube fluorescent light has a cylinder, and the sun has a disc. This means several things for representing light from the real world inside the computer.

  • Light from an area source of appropriate size looks more natural. This is because our brains perceive light strength and size based on reflections of the actual light and the relative softness (spread) of the shadow.
  • Recreating real-world lighting should be more natural because you should think in terms of the literal source from the set.
  • Scenes in correct scale along with their lights should need less tweaking for the correct “quality” of light.

This tutorial will go over the basics of the mental ray area light settings inside Maya. We’ll look at how to control the quality of the light and settings that work well for Brute Force Unified Sampling rendering seen in several places on the blog, starting here: Unified Sampling: Visually for the Artist

In the legacy days of Maya and mental ray, you had to create a light such as a spotlight and ‘turn it into’ or convert it to an area light. This is no longer necessary and is in fact, deprecated. Don’t let anyone see you doing it! Instead you should create an actual area light and use the mental ray rollout to create an area light.

The Area Light Attribute Editor

Some things to notice under the attributes:

1. Color: Obviously the color of the light. Sometimes replaced with a utility such as the mib_blackbody. Keep in mind from previous posts that for correct linear workflow you need a Gamma node here if you are simply going to choose a color from the color picker; correct it using gamma 0.4545 since Maya colors are sRGB. This corrects to linear color workflow: sRGB -> Linear Color: Linear Color Workflows in Maya: Part 1

2. Intensity: This is the strength of the light. Incidentally this does not match anything like watts, etc.

3. Decay Rate: To maintain a physically correct light source this should be set to Quadratic. In doing this you will find that your intensity will have to be increased very much depending on your scene scale. High values are perfectly fine.

Falloff Type (Quadratic is physically accurate)

Lastly, time to turn “on” the mental ray area light shape. Under the mental ray rollout there is: Area Light -> Use Light Shape. Tick this “on”.

Place this in a scene with the quintessential “sphere on a plane” setup and hit render current frame.

It probably looks atrocious (unless you’re savvy enough to have already set up your scene for Unified Sampling, but even now we can probably improve your result.)

Area lights can introduce grain into your render. Why?

In order to correctly see an area light, the point being shaded needs to sample it. In doing this the shader will send rays back to the area light to try and see as much as possible. These points are spread across the surface of the light to avoid a regular pattern in exchange for noise that is more pleasing. Such a pattern might look very similar to that used for QMC sampling.

You can control this locally for the light.

How do you make sample decisions based on the light and the scene?

First lets do a few different things to the light.

Turn on shadows in the light. I cannot for the life of me understand why the default for Maya lights is still no shadow. It is the year 2012, do not fear shadows. Maya 2014 has thankfully changed the defaults to those you see here for shadows. See the post on what has changed here: mental ray changes for Maya 2014

Shadows Settings

In this section you will see:

1. Color: Leave it black. In the past you would change this to “fake” an indirect light by giving it some color to mimic. We will assume you are using modern illumination techniques like Final Gather in your scene. Leave it black.

(You see I have collapsed the section for Depth Map Shadow Attributes. They are used less often now that raytracing is relatively less expensive. They will be covered later.)

2. Shadow rays: The Autodesk light shader allows you to resolve grain in a shadow by adding more local samples in different lights from the area light to point, spot, etc. We will use a different control for this, leave it at 1 (Simplify your life by reducing the places you go to for settings.)

3. Ray Depth Limit: This is a bit more tricky and also relies on the global raytracing settings found here:

Global Raytracing Settings

This setting along with the global setting above restricts how may times a ray may bounce for a reflection or refraction and still generate shadow samples (to make them visible in a reflection or refraction.)

Zap explained these settings here: Maya’s Default Shadow Settings

For simplicity I will restate them here with his images and update them a bit.

In order for a shadow to be seen in a reflection or refraction you must allow the shader to call the shadow after the ray has been reflected or refracted. mental ray will count down the number of times this happens and eventually tell it not to sample for shadows (cast shadow rays) You see below this affects even transparent (colored) shadows and can make your scene look incorrect. Notice the red transparent rectangle and the view behind it.

Shadow Depth: 1

Shadow Depth: 3 (both light AND render settings)

This is a useful optimization because shadow rays can be very expensive to propagate everywhere, especially from area lights. The defaults he mentions (2 for ray depth) are generally visibly acceptable for many scenes. Especially those with blurry reflections where such an effect isn’t noticed at all. However, a depth of 3 may provide you with the best quality if you can afford a little extra time. You will notice that the Final Gather preprocess phase will see the shadows at a depth of 3 (this is a Maya specific bug, 3 is also now the default in Maya 2014).

Ok, so how do you make the light and shadows look good?

Area lights have a section under the mental ray controls to provide samples. So let’s look at the settings you maybe have typically seen before Unified Sampling appeared.

Typical Area Light Samples

I have seen this section abused time to time.

1. High Samples: this is the amount of samples to shoot (draw) towards the light when an eye ray strikes an object. This means primarily visible. You want this to be your most important level of quality.

1a. The larger and closer the area light is, the more samples you may need

1b. Inversely, the smaller and further away it is, the fewer samples you need

2. High Sample Limit: Once this number of combined reflections/refractions is exhausted, the sample can draw fewer samples as defined by the Low Samples setting.

3. Low Samples: this is the amount of samples to draw for a sample taken after the number of reflections/refractions in the High Sample Limit have been exhausted.

4. Visible: Will the area light be visible in the render. In the case of the Portal Light shader it must be on to work correctly. The mia_material will also skip generating a specular highlight for a visible area light by default. This is desired because a spec is a fake for a direct reflection of a light with no area. A light with actual area should genuinely reflect in the object. Doing both doubles the energy incorrectly.

In many cases I see the High Sample Limit set to 16 or 32 without any understanding of what it really does. In this case up to a combination of 16 or 32 reflections/refractions will still draw 32 samples. In a scene with a lot of raytracing effects and depth, that’s murder on render time. Or similarly I see the Low Samples set to something obscene like 64!

These examples were rendered with fixed pixel samples of 4 so only the effect of the area light samples is taken into account.

High Samples: 1

High Samples: 4

High Samples: 16

Notice that changing the Area Light Samples locally reduced grain in not only the shadows, but the highlights and directly lit areas as well. This is also why low Quality or samples for the Native (builtin) IBL can show grain on highlights, etc. It is a similar effect. So for your overall quality you can use one set of controls and then allow Unified Sampling to choose more when necessary. Also keep in mind that multiple overlapping lights on the same area can get away with fewer samples individually as these will add up on the area being sampled and show less grain (assuming the lights aren’t creating a high contrast color difference.)

Using Unified Sampling and changing the size of the area light:

Area Light Size 1

Area Light Size 1

Area Light Size 5

Area Light Size 5

Be careful with scaling an area light when you have a custom shader attached. Some shaders will scale the intensity of the light based on size. In many cases this is correct and desired for the shader, but it is not the default behavior.

What about Unified Sampling and Brute Force?

In testing scenes with large and multiple area lights (10+) as well as special area lights like the Native (builtin) IBL, we found low but not single samples are best.

Generally speaking, a range from 4 to 8 is good. And in fact we have set the samples to (High, High Limit, Low) 4 1 4 or 6 1 4 and variations with good results.

Area Light Samples 4 generates more eye rays from Unified Sampling. This means it’s good for Depth of Field or Motion Blur where more eye rays are already useful for the overall effect and multiplying these is less expensive. Area Light Samples 8 produces fewer eye rays but at the cost of more shadow rays; this might be useful for a still frame. Area Light Samples 6 seems to be a good middle ground when used with Brute Force Unified Sampling. (Best of both worlds)

Quick metric: In an unreleased still (hopefully to be added later) I can render a car interior full frame at 6000 x 3376 with 11 area lights and brute force Unified Sampling in 2.5 hours. These area lights were set to 4 1 1 because the majority of reflections were very blurry/soft for leather and cloth.

Additional Notes:

  • Some versions of Maya have a bug in mental ray where the Shadow Limits for area lights always reach 3. So setting a lower limit will have no effect. More recent updates may have introduced a fix for the bug. (I am not on SP1 here.)
  • Autodesk uses their own way of making light shaders to mimic legacy lighting. In some situations this is not desirable (in the case pointed out by Jeff Patton; where the center of an area light may be brighter on a surface. Although very subtle, it can be annoying.)
  • Further optimize your scene by selectively choosing what object may cast or receive shadows. For example: a car window may not need to generate shadow samples or even receive them to look good.
  • Understand that “clear” and “colorless” for shadow objects are not the same concept. Windex is clear, but it’s blue and should cast a blue shadow. Clean water is clear and colorless.
  • When you have a lot of art directed imagery with lots of lights, you can reduce indirect illumination quality without image quality loss. This is especially helpful with lots of area lights.
  • The Native IBL is a giant area light. When using this on exteriors and other images you can greatly reduce Final Gather settings since it will only return secondary lighting information.
  • Area Lights generate multiple samples per eye ray sample. When you naively layer shaders this will increase the number of rays linearly. For example: plugging in a shader to the additional color of a mia_material and then assigning it will double the number of rays shot (For this example 2 shaders are run for the light loop: 2 * total lights * samples = a lot of rays) Try to avoid this by keeping networks simple or using mib_interpolate to use importance and weight to run a shader layer.
  • Use further optimizing like the threshold for the physical light: Optimizations: Lighting and Thresholds
  • In the render settings you will see an option for Sample Lock underneath Jitter. Sample Lock keeps similar sampling patterns across frames. In the case of Area Lights you may see a static noise pattern slide over your animation frame to frame. Disable this feature to randomize the pattern and generate noise which may be acceptable when seen in motion.
  • I didn’t use depth map shadows. Mostly because I am using Unified Sampling and want a fast and accurate setup. If I were using the rasterizer, need lots of soft shadows, and want motion blur, then I would possibly use Detail Shadow Maps. Detail Shadow Maps can generate very slowly at first but motion blurring them is inexpensive. I can also save a detail shadow map for certain parts of a scene (or a whole scene) and reuse them from disk at significant time savings. But for now we’re focused on raytracing and simplicity.