Category Archives: Lighting
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:
- 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.
Now try the Environment Light alone!
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?
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):
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)
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.
What are the controls?
First: I want you to realize this is NOT the Maya IBL “emit light” option.
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.)
- 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.
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.
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.
- 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.
Here’s another spot rendered with mental ray.
The environment and car were rendered and composited with live action ink and effects from Houdini.
Originally envisioned as a filmed piece, it was decided later that the car and environment would be replaced with a purely rendered version. The artists matched the shot car so closely it was impossible to tell the difference. This allowed the freedom to change how the commercial was shot while maintaining the original look and feel the director desired.
Take a look here: 2013 Toyota Avalon: Formula
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.
- 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.
- 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.
First, let’s look at the 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"
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.
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
A final area light:
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.
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
Now render with Unified Sampling. The following image was rendered using a backplate and HDR from: HDR Labs.
- 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.
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.
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.
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
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:
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.
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.
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.
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:
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.
- 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.