Chapter 9. mental ray Lights

To achieve professional-quality, realistic renders in Maya, you need to master the mental ray render plug-in that comes with Maya. mental ray is a complex rendering system that is incorporated through the Maya interface. Learning how to use it properly and efficiently takes time, study, and practice. Chapters 9 through 12 discuss various aspects of working with mental ray, starting with how to set up mental ray light nodes.

In this chapter you will learn to:

  • Use shadow-casting lights

  • Render with Global Illumination

  • Render with Final Gathering

  • Use Image-Based Lighting

  • Render using physical sun and sky

  • Understand mental ray area lights

  • Work with mental ray light shaders

  • Create Participating Media

Shadow-Casting Lights

There are two types of shadows that can be created in mental ray and several methods for creating them. The two shadow types are cast shadows and ambient occlusion. Any combination of cast shadows and ambient occlusion can be used in a mental ray scene.

Cast shadows are created when an object blocks the rays of light coming from a light source from reaching one or more other surfaces. Cast shadows are the most familiar type of shadow, and they are often a good indication of the type, location, and orientation of the light source casting the shadow.

Ambient occlusion occurs when indirect light rays are prevented from reaching a surface. Ambient occlusion is a soft and subtle type of shadowing. It's usually found in the cracks and crevices of 3D objects and scenes.

In this section, you'll create and tune cast shadows using lights in mental ray. Ambient occlusion is discussed later in the chapter in the "Indirect Lighting" section.

A light source in a Maya scene casts either ray trace or depth map shadows. When you create a light in Maya, its shadows are turned off by default. To activate shadow casting, you can open the Attribute Editor for the light's shape node and activate either depth map or ray trace shadows. You can use both depth map and ray trace shadows together in the same scene, but each light can only cast one or the other type of shadow.

Shadow Preview

When you create a shadow-casting light in a Maya scene, you can preview the position of the shadow in the viewport window.

  1. Open the car_v01.ma scene from the chapter9scenes directory on the DVD.

    This scene shows a futuristic three-wheeled vehicle on a simple, flat plane. The shaders used for the vehicle are very simple. When setting up lights for a scene, it's usually a good idea to use simple shaders as you work. This makes test rendering faster and also keeps the focus on how the lighting will work within the composition. Later on, as you refine the lighting of the scene, you can add more complex shaders and textures.

  2. Create a spotlight by choosing Create

    Shadow Preview

    To position the spotlight, use the Move and Rotate tools. You can also look through the light as if it were a camera, which is often a faster and easier way to place the light in the scene.

  3. Select the spotlight, and from the pPanels menu choose Panels

    Shadow Preview
  4. The green circle at the center of the view represents the cone angle of the spotlight. Open the Attribute Editor for the spotLight1 object, and click the spotLightShape1 tab. Set the cone angle to 90. The light from the spotlight now covers more area in the scene.

  5. Switch to the renderCam view in the viewport (from the viewport Panels menu choose Panels

    Shadow Preview
  6. In the viewport Panels menu, choose Lighting

    Shadow Preview
    View the scene from the position of the spotlight.

    Figure 9.1. View the scene from the position of the spotlight.

    At the moment, the preview of the light looks very blocky. You can improve the quality of the light preview by selecting the ground plane and increasing its subdivisions.

  7. Select the ground plane and open the Channel Box. In the INPUTS section, set Subdivisions Width and Height to 30.

  8. In the Panels menu, choose Lighting

    View the scene from the position of the spotlight.

    You won't see any shadows until you activate shadows for the lights in the scene.

  9. Select the spotLight1 object and open its Attribute Editor and click on the spotLightShape1 tab. Expand the Shadows section and activate Use Depth Map Shadows. A preview of the shadow appears on the ground plane. The preview looks the same regardless of whether you use depth map or ray trace shadows (Figure 9.2).

  10. Select the spotlight, and use the Move and Rotate tools to change its position and rotation. Observe the changes in the preview. The preview will most likely slow down the performance of Maya, so use this feature only when you are positioning lights.

  11. Scroll to the top of the spotlight attributes and set Type to Directional. Notice the difference in the shape of the shadow.

    Activate a preview of the spotlight's shadow in the scene.

    Figure 9.2. Activate a preview of the spotlight's shadow in the scene.

    The shadow preview works only for spotlights and directional-type lights.

  12. Switch Type back to Spotlight. With the spotlight selected, click on the Show Manipulators tool at the bottom of the toolbar.

The Show Manipulators tool has both aiming and positional manipulators that can help you set up your lights. Click on the small switch to the right of the spotlight to cycle through the different manipulators (Figure 9.3). If you want to know what each manipulator does, click on its handle, and you'll see a short description in the help line at the lower left of the Maya interface.

The Show Manipulators tool displays interactive control handles for the spotlight.

Figure 9.3. The Show Manipulators tool displays interactive control handles for the spotlight.

Depth Map Shadows

Depth map shadows (also known as shadow maps) are created from data stored in a file that is generated at render time. The file stores information about the distance between the shadow-casting light and the objects in the scene from the light's point of view. Depth map shadows usually take less time to render than ray trace shadows and produce excellent results in many situations.

When using mental ray, you can choose to use Maya's native depth map shadows or to use mental ray's own depth map format. In this exercise, we will compare the results produced using various depth map shadow settings.

  1. Open the car_v02.ma scene from the chapter9scenes directory on the DVD. In this version of the scene, the car has a simple white Lambert shader applied.

    Using a simple flat shader speeds up the render and allows you to focus on how the shadows look on the surfaces without the distraction of reflections and specular highlights.

  2. Open the Render Settings window (Window

    Using the mental ray Plug-in
    Choose the Production preset in the mental ray Quality tab.

    Figure 9.4. Choose the Production preset in the mental ray Quality tab.

  3. Choose Create

    Loading mental ray
  4. Open the Attribute Editor for spotLight1, and click the spotLightShape1 tab. Set Cone Angle to 90. Scroll down to the Shadows section and activate Use Depth Map Shadows.

  5. Choose Window

    Loading mental ray

    The Render View window is where you can preview your renders as you work. As you create renders, you can store the images and compare them with previous renders. You can also create Interactive Photorealistic Renders (IPRs), which update interactively as you change certain scene elements. IPR is discussed in more detail in Chapter 10.

  6. From the Render View menu, choose Render

    Loading mental ray

    You'll see the render appear in the window after a few seconds. By default, the quality of depth map shadows is pretty poor. With some tweaking you can greatly improve the look of the shadows.

    The shadow is generated using a special depth file, which is an image. As such, the image has a resolution that is controlled by the Resolution slider. When the resolution is low, you can see a visible grainy quality in the shadows, as shown in Figure 9.5.

    The default depth map shadows have a grainy quality.

    Figure 9.5. The default depth map shadows have a grainy quality.

    To improve the look of the shadow, you can balance the resolution with the filter size.

  7. Set Resolution to 2048 and Filter Size to 0. Create a test render in the render view, and store the image in the Render View window (in the Render View menu choose File

    View Depth Map Files
  8. Set Resolution to 512 and the Filter Size to 5. Create a test render, store the render in the Render View window, and use the scroll bar at the bottom of the render view to compare the two images (Figure 9.6).

    Two renders using depth map shadows. The left side uses a high-resolution map with no filtering; the right side uses a low-resolution map with high filtering.

    Figure 9.6. Two renders using depth map shadows. The left side uses a high-resolution map with no filtering; the right side uses a low-resolution map with high filtering.

    Using a low resolution (such as 512) and a high filter size (such as 5) creates soft shadows, the kind you might expect on an overcast day. One weakness in using a high filter size is that the blurring is applied to the entire shadow. In reality, shadows become gradually softer as the distance increases between the cast shadow and the shadow-casting object.

    The Use Mid Dist feature is enabled by default. This option corrects banding artifacts that can occur on curved and angled surfaces (Figure 9.7). The Mid Dist Map is a second image file that records the points midway between the first surface encountered by the light and the second surface encountered by the light. The second image is used to modify the depth information of the original depth map file to help eliminate banding artifacts.

    When Use Mid Dist is disabled, artifacts can appear on the surface.

    Figure 9.7. When Use Mid Dist is disabled, artifacts can appear on the surface.

    The Bias slider provides a similar function for eliminating artifacts. The slider adjusts the depth information in the depth map file. Increasing the bias pushes surface points closer to the shadow-casting light to help eliminate artifacts. This transformation of surface points occurs in the depth map file, not in the actual geometry of the scene.

    If you are encountering artifacts on the surface of objects and Use Mid Dist is enabled, you can use the Bias slider to reduce the artifacts. Change the bias values in small increments as you create test renders. If the bias is too high, you'll see a gap between the shadow-casting object and the shadow.

    The Use Auto Focus setting automatically adjusts the objects within the field of the light's viewable area to the maximum size of the shadow map resolution. So if, from the light's point of view, an object is surrounded by empty space, the light will zoom into the object in the depth map image. This helps optimize the use of the pixels within the depth map image so that none are wasted. It's usually a good idea to leave this setting enabled when using spotlights; however, you may encounter a different situation with other types of lights.

  9. Set Resolution of the depth map to 512 and Filter Size to 0.

  10. Scroll up in the Attribute Editor, and set Light Type to Directional. Create a test render and store the image.

  11. Select the ground plane object, and set its Scale X and Scale Z values to 500. Create another test render, and compare it to the last render created.

The shadow is very blocky when the size of the ground plane is increased (see Figure 9.8).

When the size of the ground plane is increased, depth map shadows cast by directional lights appear very blocky.

Figure 9.8. When the size of the ground plane is increased, depth map shadows cast by directional lights appear very blocky.

When using spotlights, the size of the viewable area from the light's point of view is restricted by the cone angle and the distance between the light and the subject. When using directional lights, the size of the viewable area is always adjusted to fit all of the objects in the scene. This is because directional lights do not factor in their position in the scene when calculating shadows, only their orientation.

In this situation you may need to create a separate shadow pass for your lights or use ray trace shadows. Render passes are covered in Chapter 12.

mental ray Shadow Map Overrides

The mental ray overrides offer settings that are similar to the standard Maya shadow maps. In addition to the Resolution setting, there are also Samples and Softness settings. The Softness setting is similar to the Filter Size attribute for Maya shadow maps. You can click the Take Settings From Maya button to automatically load the settings created for standard Maya shadow maps into the mental ray attributes.

  1. Open the car_v02.ma scene from the chapter9scenes directory on the DVD. In the Render Settings window, set Render Using to mental ray. On the Quality tab, set Quality Presets to Production.

  2. Select the spotlight, and open the Attribute Editor to the spotlightShape1 tab. In the Shadows section, turn on Use Depth Map Shadows.

  3. Scroll down to the Attribute Editor, expand the mental ray rollout, and expand the Shadows section under mental ray.

  4. Check the Use mental ray Shadow Map Overrides box. This activates the Shadow Map Overrides section, giving you access to mental ray controls for shadow maps.

  5. Set Resolution to 2048 and Softness to 0.025. Create a test render. Store the image in the Render View window. The render is very similar to the results seen before, very grainy.

  6. Set Samples to 64, and create another test render. The graininess is reduced without significantly impacting the render time. Store the image in the render view.

    Detail shadow maps are a more advanced type of shadow map that stores additional information about the surface properties of shadow-casting objects. This information includes surface properties such as transparency. In the current scene, enabling Detail Shadow Map can reduce the shadow artifacts visible on the surface of the car (see Figure 9.9).

  7. Set Shadow Map Format to Detail Shadow Map, and create another render. Use the scroll bar at the bottom of the render view to compare this render with the previous two renders (Figure 9.10).

    Detail shadow maps are more sensitive to changes in the Softness setting. There are also additional Samples and Accuracy settings that can be used to tune the quality of the maps. You can use the Shadow Map File Name field to set a name for saved shadow maps and then reuse the shadow maps to improve render time. The settings for saving shadow maps are found in the Shadows section of the Render Settings window under the Quality tab.

  8. Save the scene as car_v03.ma. To see a version of the scene to this point, open the car_v03.ma scene from the chapter9scenes directory on the DVD.

Enable Detail Shadow Map in the mental ray Shadows settings.

Figure 9.9. Enable Detail Shadow Map in the mental ray Shadows settings.

The car is rendered with Samples set to 1 (left image), Samples set to 64 (middle image), and Detail Shadow Map enabled (right image).

Figure 9.10. The car is rendered with Samples set to 1 (left image), Samples set to 64 (middle image), and Detail Shadow Map enabled (right image).

Ray Trace Shadows

Ray trace shadows are created by tracing the path of light rays from the light source to the rendering camera. Using ray trace shadows produces more accurate results but often takes a little more time and processor power to calculate.

Some advantages ray trace shadows have over shadow maps include the following:

  • Ray trace shadows created with area lights become softer and lighter as the distance increases between the shadow and the shadow-casting object.

  • Ray trace shadows can be accurately cast from transparent, refractive, and colored objects.

To activate ray trace shadows, make sure Raytracing is enabled in the Quality tab of the mental ray Render Settings window, and enable Use Ray Trace Shadows for the light. When you choose the Production Quality preset for mental ray, Raytracing is enabled by default (see Figure 9.11).

Ray trace shadows are typically very crisp when enabled. To add softness to the shadow, increase the Shadow Rays and the Light Radius values in the Raytrace Shadow Attributes section. In Figure 9.12 you can see how increasing the Light Radius and the Shadow Rays values adds softness to the shadow. The render in the left image uses a Light Radius of 0 and a Shadow Rays setting of 1. The render in the right image has a Light Radius of 1, and Shadow Rays is set to 40. Notice that the blurring on the shadow increases as the distance between the shadow and the shadow-casting object increases.

Raytracing is enabled in the mental ray Render Settings window, and Use Ray Trace Shadows is enabled for the light.

Figure 9.11. Raytracing is enabled in the mental ray Render Settings window, and Use Ray Trace Shadows is enabled for the light.

Add softness to ray trace shadows by increasing the Light Radius and Shadow Rays settings.

Figure 9.12. Add softness to ray trace shadows by increasing the Light Radius and Shadow Rays settings.

Increase the Ray Depth Limit value when you need a shadow to be visible in reflections. Each level of the Ray Depth Limit corresponds to the number of transparent surfaces between the light and the shadow (Figure 9.13).

When Ray Depth Limit is set to 1, the shadow is not visible in the reflection (left image). When it is set to 2, the shadow is visible (right image).

Figure 9.13. When Ray Depth Limit is set to 1, the shadow is not visible in the reflection (left image). When it is set to 2, the shadow is visible (right image).

Indirect Lighting: Global Illumination

In reality, when a ray of light hits an opaque surface, it is either absorbed or reflected (or a little of both) by the surface. If the light ray is reflected, it reenters the environment and continues to bounce off reflected surfaces until it is absorbed by another surface. Objects illuminated by reflected light are thus lit indirectly.

mental ray has several methods for simulating indirect lighting: Global Illumination, Final Gathering, and Ambient Occlusion shaders. These can be used separately or together depending on what you are trying to achieve in your render.

In this section, you'll get some hands-on experience working with the Global Illumination and Final Gathering. Using ambient occlusion will be discussed in Chapter 10.

Global Illumination

Global illumination simulates photons of light bouncing off geometry in a Maya scene. It is actually a two-step process. The photon-emitting light shoots out photons into a scene. A photon map is created that records the position of the photons and their intensities in three-dimensional space. Then the area is searched for surfaces that intersect the photons, the surfaces are illuminated based on the intensities of the intersecting photons, and the diffuse value of the shader is applied to the surface.

Glossy, black, or reflective surfaces with no diffuse value will not be affected by global illumination; a diffuse value must be present. The second part of the process is the actual rendering of the image. The photon map is stored in a data structure known as a Kd-Tree. During rendering, the energy values are averaged over a given radius in the Kd-Tree, and these values are interpolated to create the look of light bouncing off the diffuse surfaces. The great thing about this method is that once you have perfected the look of the global illumination, if the elements of the scene are fairly static, you can save the photon map and reuse it in the scene, cutting down on the amount of time required to render each frame.

In this exercise, you'll use global illumination to light a simple temple scene. There are no textures or color in the scene, so you can focus specifically on how global illumination reacts with surfaces.

  1. Open the temple_v01.ma scene from the chapter9scenes directory on the DVD. In the scene a camera named renderCam has already been created and positioned.

  2. Create a directional light and place it outside the window; rotate the light so it's shining in the window (the position of a directional light does not affect how it casts light—only the rotation does—but it's convenient to have it outside the window). Use these settings in the Channel Box:

    • Translate X: 0

    • Translate Y: 21

    • Translate Z: −16.85

    • Rotate X: 143.7

    • Rotate Y: 3.5

    • Rotate Z: 180

  3. In the Attribute Editor, switch to the directionalLightShape1 tab. Turn on Use Depth Map Shadows. Set the Resolution slider to 1024, and set Filter Size to 0.

  4. Create a test render in the render view using the renderCam camera. The image should look very dark except for the outline of the window on the floor.

  5. Open the Render Settings window, and switch to the Indirect Lighting tab. Expand the Global Illumination rollout, turn on Global Illumination, and use the default settings (see Figure 9.14).

  6. In the Attribute Editor settings for directionalLightShape1, expand the mental ray rollout and, under Caustic and Global Illumination, activate Emit Photons. Create another test render. The resulting render should look pretty horrible.

    Activate Global Illumination in the Render Settings window, and use the default settings for the light.

    Figure 9.14. Activate Global Illumination in the Render Settings window, and use the default settings for the light.

    Using a directional light is a perfectly reasonable choice for creating the look of light coming through a window. The light rays cast by a directional light are parallel, which simulates the way light from a distant source, such as the sun, behaves. However, directional lights tend to have an overexposed quality when used as photon-casting lights (see Figure 9.15). This is because the photons cast from a photon-emitting light need to have both a direction and a position. Directional lights have only a direction (based on the rotation of the light), so the light often casts too many photons, and artifacts can result. It's a good practice to avoid directional lights altogether as photon-casting light. The best types of lights to use are area, spot, and point. Area lights tend to work the best since they cast light from a sizeable area as opposed to a point in space.

    When a directional-type light is used to cast photons, the result is a blown-out image.

    Figure 9.15. When a directional-type light is used to cast photons, the result is a blown-out image.

    The photon-casting properties of a light are completely separate and unrelated to the light's intensity. In practice, it's often a good idea to use one light to cast direct light as well as to create cast shadows, and another light to create the indirect light.

    If you are in a situation where the same light is casting direct and indirect illumination, raising the intensity can cause the area around the light to become overexposed. In this situation, you may want to use two lights placed near each other. One light should cast only direct light (that is, Cast Photons is disabled), and the other light should have 0 Intensity but Cast Photons should be enabled.

  7. In the Attribute Editor for the directional light, turn off Emit Photons in the Caustic And Global Illumination settings. Rename the light Sun.

  8. Create an Area Light (Create

    When a directional-type light is used to cast photons, the result is a blown-out image.
    • Translate X: −1.816

    • Translate Y: −0.227

    • Translate Z: 11.555

    • Rotate X: 90

    • Scale X: 3

    • Scale Y: 3

    • Scale Z: 3

  9. Open the Attribute Editor for Bounce. Turn off Emit Diffuse and Emit Specular. Set Intensity to 0.

  10. In the mental ray rollout, turn on Emit Photons. Create a test render of the scene, and store the image in the Render View window.

    The render is a big improvement, although clearly the default settings are not adequate and require some tuning, but it looks less like a nuclear blast.

  11. The image looks a little weird because there is sunlight coming through a black window. To create a quick fix for this, select renderCam and open its Attribute Editor. In the Environment tab, set the background color to white. Create another test render. (Figure 9.16).

  12. Save the scene as temple_v02. To see a version of the scene to this point, open the temple_v02.ma scene from the chapter9scenes directory on the DVD.

Photons are cast from an area light placed on the floor of the temple. When the background color for the camera is set to white, the area outside the window is white.

Figure 9.16. Photons are cast from an area light placed on the floor of the temple. When the background color for the camera is set to white, the area outside the window is white.

Tuning Global Illumination

Adjusting the look of the global illumination requires editing the settings in the area light's Attribute Editor and in the Render Settings window. The settings work together to create the effect. Often you'll tune the lighting of the scene by adjusting and readjusting the various settings until you get the best result you can.

  1. Continue with the scene from the previous section or open the temple_v02.ma file from the chapter9scenes directory on the DVD.

  2. Select the Bounce light, and open its Attribute Editor to the bounceShape tab. Expand the mental ray rollout in the Attribute Editor. Under Area Light activate Use Light Shape. Set Type to Disc. This will match the shape of the sunlight cast on the floor.

  3. Take a look at the settings under Caustics And Global Illumination:

    • Emit Photons turns on the photon-casting property of the light.

    • Photon Color adds color to the actual photons.

    • Photon Intensity controls the energy of the photons as they are shot into the room and how they are reflected from various sources.

    • Exponent controls the photon decay rate. A setting of 2 is consistent with the inverse square law, which states that the intensity of light is inversely proportional to the square of the distance from the source. A setting of 2 would be analogous to setting a light's Decay rate to Quadratic. This simulates how light actually works in the real world. Setting Exponent to 1 is analogous to setting a light's Decay setting to Linear, which is closer to how light from distant bright sources, such as the sun, decays.

    • Global Illum Photons is the number of photons cast into the room by the photon-casting light. Increasing this value often aids in the look of the effect. The more photons you add, the longer the render can take in some cases.

  4. The indirect lighting looks a little blown out. Lower Photon Intensity to 5000.

    The blotchy quality on the wall is caused because there are not enough photons being cast by the light. Increasing the number of photons creates more overlapping and thus smoothes the look of the light as it reflects from the surface.

  5. Set Global Illum Photons to 80000. Create a test render (Figure 9.17).

    By decreasing Photon Intensity and increasing Global Illum Photons, the lighting is improved.

    Figure 9.17. By decreasing Photon Intensity and increasing Global Illum Photons, the lighting is improved.

  6. Open the Render Settings window, and click the Indirect Lighting tab. Take a look at the Global Illumination settings.

    • Global Illumination turns on global illumination calculations. Some mental ray presets, such as Preview Global Illumination, activate this option when chosen. Notice the Caustics check box above. This activates the caustics calculations, which are separate from Global Illumination; this will be explained further on in the chapter.

    • Accuracy sets an overall level of accuracy in the Global Illumination calculations. If this is set to 1, the photons are not blended together at all, and you can see the individual photons (Figure 9.18). Generally it's a good idea to keep Accuracy between 250 and 800 for most situations.

      Lowering the Accuracy setting in the Render Settings window reveals the individual photons as they are reflected on surfaces.

      Figure 9.18. Lowering the Accuracy setting in the Render Settings window reveals the individual photons as they are reflected on surfaces.

    • Scale can act as a global brightness control for the global illumination effect.

    • Radius controls the radius of the actual photons. When this is set to 0, mental ray determines the radius of the photons based on the requirements of the scene. The radius is not actually 0. Increasing the radius can smooth the photons; however, too large an area can cause a loss of detail in the shadows and color bleeding, which leads to a blurry, undefined sort of look.

    • Merge Distance specifies a distance in world space within which overlapping photons are merged. This is used to reduce the size of photon maps and increase render times. You should raise this setting by very small increments. It can increase the blotchy look of the render.

  7. Click on the color swatch next to Scale to open the Color Chooser. Set the value (V) to 1.2 and create another test render. This is a good way to brighten the overall global illumination effect without raising the Photon Intensity value on one or more lights (Figure 9.19).

  8. Save the scene as temple_v03.ma. To see a version of the scene to this point, open the temple_v03.ma scene from the chapter9scenes directory on the DVD.

Working with Global Illumination requires a lot of testing and tuning. At a certain point, you'll need to combine the techniques with other indirect lighting tools such as Final Gathering to perfect the look.

Raising the Scale value brightens the overall effect of Global Illumination.

Figure 9.19. Raising the Scale value brightens the overall effect of Global Illumination.

Working with Photon Maps

Photon maps are generated during a mental ray render using Global Illumination. They store the position, energy, color, and other data associated with the photons cast during render. The map can be saved to disk and reused to cut down on render time. This, in fact, eliminates the first stage of rendering with Global Illumination on subsequent renders.

Of course, if there is a lot of animation in the scene, reusing the same map will not always work, but in a scene such as the current one it can be quite helpful.

To save a photon map, type a name for the map in the Photon Map File field (found in the Photon Map section in the Indirect Lighting tab of the Render Settings window), and create a render (do not add a file extension to the name). When you want to reuse the same map, uncheck Rebuild Photon Map. The map is stored in the renderDatamentalRayphotonMap directory with the .pmap extension. When you want to overwrite the map, simply check Rebuild Photon Map.

Remember to turn on Rebuild Photon Map when you make changes to the scene. Otherwise the scene will not update correctly as you create test renders.

The Enable Map Visualizer option is a way to visualize how the photons are cast in the scene. When you enable this and create a Global Illumination render, you'll see dots spread about the scene in Maya's camera view, representing the distribution of photons cast by the light.

  1. Type test into the Photon Map File field in the Photon Map section of the Indirect Lighting tab in the Render Settings window.

  2. Check Rebuild Photon Map and Enable Map Visualizer.

  3. Open the render view, and create a test render from the renderCam.

  4. Close the render view when the render is complete. Look at the perspective view in Maya. You should see the geometry covered in dots representing the distribution of photons created by the bounce light.

  5. Choose Window

    Working with Photon Maps
  6. To remove the dots, select the mapViz1 node in the Outliner and delete it. This will not affect the render or the saved photon map.

The map Visualizer allows you to see how the photons are cast in the scene.

Figure 9.20. The map Visualizer allows you to see how the photons are cast in the scene.

The dots in the scene can be colored based on the Photon Color of the light; you can use this to diagnose how each photon-casting light is affecting the scene. Also, if you save more than one photon map, you can load and view them using the Enable Map Visualizer option. Use the Map File Name dialog box to load saved maps.

Another way to visualize the photons in the scene is to use the Diagnose Photon menu. When you choose a setting from this menu and create a render, the shaders in the scene are replaced with a single shader colored to indicate either the photon density or the irradiance of surfaces in the scene (irradiance is discussed a little later in this chapter).

Color Bleeding

When light is reflected from a colored surface, the color can mix with the indirect light. mental ray's Global Illumination can simulate this property.

  1. Open the temple_v04.ma scene from the chapter9scenes directory on the DVD. This scene has a globe model added close to where the sunlight strikes the floor.

  2. The model has a Lambert shader applied with bright yellow set for the color. Create a test render. You'll see the yellow color bleed onto the surrounding area of the temple.

Color bleeding is a part of Final Gathering and occurs automatically when colored objects are near the photon-emitting lights.

Importons

Importons are very similar to photons. Importons are emitted from the camera and bounce toward the light. Photons, on the other hand, are emitted from the lights and bounce toward the camera, so importons actually move in the opposite direction of photons. You can use importons to improve the quality of global illumination maps.

The Importons controls are found under the Indirect Illumination tab in the Global Illumination Controls of the Render Settings window. Importons are available only when Global Illumination is enabled.

When you render using importons, mental ray first calculates the importon emission and then renders the scene. The importons are discarded when the render is completed.

The Density value of the importons controls how many importons are emitted from the camera per pixel. Generally this value does not need to be higher than 1. The Merge setting works very similarly to the Merge setting used for photons. The Traverse feature maximizes the number of importons in the scene; it's generally a good idea to leave this option on.

You can improve the quality of Global Illumination renders by activating the Importons option. The option must be turned on in the Indirect Lighting tab in the Render Settings window and also in the Features tab of the Render Settings window. The right image in Figure 9.21 shows the temple scene rendered using Global Illumination, with Importons turned off. The left image shows the same render with Importons turned on. The default settings are used for the Importons controls.

The right image is rendered without importons; the left image is the same render with Importons activated.

Figure 9.21. The right image is rendered without importons; the left image is the same render with Importons activated.

Caustics

Global Illumination simulates light reflected from diffuse surfaces. Caustics simulate light reflected from glossy and reflective surfaces as well as light that passes through refractive transparent materials. Caustics are calculated completely independently from Global Illumination; however, the workflow is very similar.

This exercise will show you how to set up and render using Caustics.

  1. Open the crystalGlobe_v01.ma scene from the chapter9scenes directory on the DVD.

    The scene contains a globe with crystalline structures emanating from the top. The globe is set on top of a metal stand. At the moment all the objects in the scene use a simple Lambert shader.

  2. In the Outliner, expand the Globe group and select the crystal object. Assign a Blinn shader to the crystal (from the Rendering menu set choose Lighting/Shading

    Caustics
  3. Set the Color of crystalShade to red and Transparency to a very light gray—almost white.

  4. In the Specular Shading section of the Attribute Editor, set Eccentricity to 0.05. Set Specular Roll Off to 1 and Specular Color to white. Set Reflectivity to 0.25.

  5. Expand the Raytrace Options rollout and activate Refractions; set Refractive Index to 1.2 (Figure 9.22).

    The settings for the crystalShade shader

    Figure 9.22. The settings for the crystalShade shader

  6. Create a spotlight. Select the spotlight and choose Look Through Selected. Aim the spotlight so it's looking down at the globe and stand. Position the light so the globe fits inside the cone angle radius (the circle at the center of the screen). Figure 9.23 shows this.

  7. Switch to the perspective view. Open the Render Settings window, and set Render Using to mental ray. In the Quality tab, set Quality Presets to Production.

  8. In the Attribute Editor for the spotlight, turn on Use Ray Trace Shadows. Create a test render of the scene.

    At the moment Caustics have not been activated. Keep this image in the render view so you can compare it with the Caustics render.

  9. Open the Render Settings window, and switch to the Indirect Lighting tab. Under Global Illumination, turn on Caustics. Leave Global Illumination unchecked.

  10. Select the spotlight. In the Attribute Editor for the spotlight, scroll down to the mental ray section. Under Caustics And Global Illumination, turn on Emit Photons.

  11. Create another test render in the render view. Immediately you can see a dramatic difference in the two renders (Figure 9.24).

    The scene is viewed from the spotlight. Position the light so the cone angle fits around the globe and stand.

    Figure 9.23. The scene is viewed from the spotlight. Position the light so the cone angle fits around the globe and stand.

    The image on the left is rendered without Caustics enabled; the image on the right has Caustics enabled.

    Figure 9.24. The image on the left is rendered without Caustics enabled; the image on the right has Caustics enabled.

    The light passing through the refractive surface produces a white highlight in the shadow on the floor. You can also see some of the red color of the globe reflected on the floor in a few spots. Notice, however, that the shadow is no longer transparent. The light that passes through the transparent globe is bent by the globe's refractive properties. This results in the hot spot seen at the center of the shadow. mental ray adds the bright spot on top of an opaque shadow.

  12. The Caustics settings are similar to the Global Illumination settings. In the spotlight's Attribute Editor, lower Photon Intensity to 3000. Set Caustic Photons to 80000.

    You can adjust the color of the caustic highlight by changing the caustic photon color or by changing the color of the transparency on the crystal shader. It's probably a better idea to change the transparency color on the shader; that way, if one light is creating caustics on two different objects that are shaded with different colors, the color of the caustic photons won't clash with the color of the objects.

    The Exponent setting for Caustics works just like the Exponent setting for Global Illumination.

  13. Select the crystal object, and open the Attribute Editor. Click the Crystal Shade tab. Set the Transparency color to a light pink.

  14. Open the Render Settings window, and click the Indirect Lighting tab. Set Accuracy of the Caustics to 32. Create a test render of the scene (Figure 9.25).

    The scene is rendered after lowering the Accuracy and the Photon Intensity settings.

    Figure 9.25. The scene is rendered after lowering the Accuracy and the Photon Intensity settings.

A lower Accuracy value produces sharper caustic highlights at the risk of some graininess. A higher value removes the grainy quality but softens the look of the caustics. You can also soften the look a little by setting Filter to Cone.

The Radius value can be left at 0 if you want Maya to determine the proper radius at render time. Settings below 1 make individual photons more visible. The Merge Distance setting merges all photons within the specified distance, which can decrease render times but remove the detail in the caustic patterns.

Caustic Light Setup

In practice spotlights are usually the best choice for creating caustics. Area lights don't work nearly as well. The cone angle of the spotlight is reduced so no photons are wasted; they are concentrated on the globe and stand. However, you may not want the visible edge of the spotlight cone on the floor. To fix this you can use two spotlights—one to create the caustic photons and the other to light the scene.

  1. Select the spotlight and duplicate it (Ctrl+d).

  2. Open the Attribute Editor for spotlight1. Under Spotlight Attributes, turn off Emit Diffuse. Under Shadows, turn off Use Ray Trace Shadows.

  3. Select spotlight2 and open its Attribute Editor. Under Spotlight Attributes, turn off Emit Specular.

  4. Set Cone Angle to 90. Turn on Use Ray Trace Shadows and turn off Emit Photons under Caustics And Global Illumination.

  5. Create a test render of the scene. The scene looks pretty much the same, but the area of light cast by the spotlight has been widened.

  6. In the Outliner, select the Stand group and apply a Blinn shader. Name the shader standShader.

  7. Open the Attribute Editor for the standShader. Set Color to a light, bright yellow. Set Diffuse to 0.25.

  8. Under Specular Shading, set Eccentricity to 0.1. Set Specular Roll Off to 1, Specular Color to white, and Reflectivity to 0.85. Create another test render. You can clearly see the light reflected off the stand and onto the floor.

    When working with Caustics, you'll get more interesting results when the caustic light patterns are created from complex objects. You'll also find that the patterns created by transparent objects vary greatly when you change the Refractive Index value of the transparent shader (Figure 9.26).

  9. Save the scene as crystalGlobe_v02.ma. To see a version of the scene to this point, open the crystalGlobe_v02.ma scene from the chapter9scenes directory on the DVD.

Apply a reflective shader to the stand, creating intricate patterns of reflected light on the floor.

Figure 9.26. Apply a reflective shader to the stand, creating intricate patterns of reflected light on the floor.

Indirect Illumination: Final Gathering

Final Gathering is another method for calculating indirect lighting. It can be used on its own or in conjunction with Global Illumination. Final Gathering uses irradiance sampling and ambient occlusion to create the look of ambient and indirect lighting. When Final Gathering is enabled, rays are cast from the camera into the scene. When a ray intersects with a surface, a Final Gathering point is created that samples the irradiance value of the surface and how it is affected by other scene elements, such as nearby objects, lights, and light-emitting surfaces.

Final Gathering uses ray tracing rather than photon casting. Each Final Gathering point that the camera shoots into the scene lands on a surface and then emits a number of Final Gathering primary rays, which gather information about the irradiance values and proximity of other scene elements. The information gathered by the rays is used to determine the shading of the surface shading normal at the location of the Final Gathering point. Imagine a hemispherical dome of rays that are emitted from a point on a surface; the rays gather information about other surfaces in the scene. Like Global Illumination, this allows it to simulate color bleeding from nearby surfaces.

The effect of ambient occlusion is created when ambient or indirect light cannot reach a surface point because it is blocked by a nearby surface. Simply put, ambient occlusion is basically a type of ambient light shadowing. Think of the dark areas you see in the cracks and crevices between objects or parts of an object on an overcast day. Final Gathering creates ambient occlusion as part of its calculation. You can also use the Ambient Occlusion shader to create this look. The Ambient Occlusion shader is discussed in Chapter 10.

Light-Emitting Objects

One of the most interesting aspects of Final Gathering is that you can use objects as lights in a scene. An object that has a shader with a bright incandescent or ambient color value actually casts light in a scene. This works particularly well for situations in which geometry needs to cast light in a scene. For example, a cylinder can be used as a fluorescent light bulb (Figure 9.27). When a shader is assigned to the cylinder with a bright incandescent value and Final Gathering is enabled, the result is a very convincing lighting scheme. In a scene like the one in this chapter, you can strategically place bright objects in areas around the room and then disable their visibility in the render. The light will be cast from the object, but the object itself will not be seen.

In this exercise, you'll light the car model used earlier in this chapter using only objects with incandescent shaders. Polygon planes will be used as so-called light cards to simulate the look of diffuse studio lighting. You'll find that it's easy to get a great-looking result from Final Gathering rendering while still using very simple, standard Maya shaders.

  1. Open the car_v04.ma scene from the chapter9scenes directory on the DVD.

  2. Open the Render Settings window and click the Common tab. Scroll to the bottom of the window and expand the Render Options rollout. Make sure the Enable Default Light option is not checked.

    A cylinder with an incandescent shader actually casts light in the scene when Final Gathering is enabled.

    Figure 9.27. A cylinder with an incandescent shader actually casts light in the scene when Final Gathering is enabled.

    The Enable Default Light option is normally on so that when you create a test render in a scene with no lights, you can still see your objects. When you add a light to the scene, the default light is overridden and should no longer illuminate the objects in the scene. However, since you won't be using actual lights in this scene, you need to disable Enable Default Light.

  3. Click the Quality tab and set Quality Presets to Production.

  4. Create a quick test render using the renderCam camera. The scene should appear completely black, confirming that no lights are on in the scene.

  5. Switch to the Indirect Lighting tab, scroll down, and activate Final Gathering. Do another test render. The scene should still be black.

  6. Select the renderCam camera in the Outliner, and open its Attribute Editor. Switch to the renderCamShape tab, scroll down to the Environment section, and set Background Color to white. Create another test render. Make sure the renderCam is chosen as the rendering camera.

    You'll see the car appear as the scene renders. There are no lights in the scene. However, the white color of the background is used in the Final Gathering calculations. You'll notice that the scene renders twice.

    The Final Gathering render takes place in two stages, much like Global Illumination. In the first pass, Final Gathering projects rays from the camera through a hexagonal grid that looks like a low-resolution version of the image. In the second stage, the Final Gathering points calculate irradiance values, and the image is actually rendered and appears at its proper quality. You'll often notice that the first pass appears brighter than the final render.

    The car has a simple white Lambert shader applied. The shadowing seen under the car and in the details is an example of ambient occlusion that occurs as part of a Final Gathering render (Figure 9.28).

    The car is rendered with no lights in the scene. The background color is used to calculate the Final Gathering points.

    Figure 9.28. The car is rendered with no lights in the scene. The background color is used to calculate the Final Gathering points.

  7. Set Background Color of the renderCam back to black. Create a polygon plane, and apply a Lambert shader to the plane.

  8. Set the Incandescence of the plane's Lambert shader to white.

  9. Use the Move and Rotate tools to position the plane above the car at about a 45-degree angle. Use the following settings in the Channel Box for the plane:

    • Translate X: −.431

    • Translate Y: 25.793

    • Translate Z: 14.072

    • Rotate X: 45

    • Rotate Y: 0

    • Rotate Z: 0

    • Scale X: 40

    • Scale Y: 20

    • Scale Z: 20

  10. Select the plane, and open the Attribute Editor to the pPlaneShape2 tab. Expand the Render Stats rollout and turn off Primary Visibility. This means that the plane still influences the lighting in the scene and can still be seen in reflections and refractions, but the plane itself is not seen by the rendering camera.

  11. Create another test render from the renderCam. The car appears much darker this time.

  12. Select the pPlane2 shape and open the Attribute Editor. Select the tab for the plane's shader, and click on the swatch next to Incandescence to open the Color Chooser. Set the value slider (V) to 4. Create another test render. The car should be more visible now (Figure 9.29).

    Raising the value of the incandescence on the shader's plane makes the car more visible.

    Figure 9.29. Raising the value of the incandescence on the shader's plane makes the car more visible.

    Using incandescent objects is a great way to simulate the diffuse light boxes used by photographers. You can easily simulate the lighting used in a studio by strategically placing incandescent planes around the car. However, you'll notice that the lighting is somewhat blotchy. You can fix this using the Final Gathering settings in the Indirect Lighting tab of the Render Settings window.

    The Final Gathering options in the render settings set the global quality of the Final Gathering render. Here is a brief description of what these settings do.

    Accuracy

    This value determines the number of Final Gathering rays shot from the camera. Higher values increase render time. A value of 100 is fine for testing; a high-quality render typically uses 500 to 800 rays.

    Point Density

    This setting determines the number of Final Gathering points generated by the rays. Increasing this value also increases quality and render time.

    Point Interpolation

    This setting smoothes out the point calculation. Increasing this value improves the quality of the result without adding too much to render time. However, as with any smoothing operation, detail can be lost at higher values.

    Primary Diffuse Scale

    Just like with Global Illumination and caustics, this scale brightens the resulting Final Gathering render.

    Secondary Diffuse Bounces

    Enabling this option allows Final Gathering rays to bounce off a second diffuse surface before terminating. This increases realism as well as render time. Final Gathering rays do most of their work on the first or second bounce; beyond that the calculations don't yield a significant difference.

    Secondary Diffuse Scale

    Increasing the value of Secondary Diffuse Scale increases the influence of the Secondary Diffuse Bounces.

  13. Set Accuracy to 400, Point Density to 2, and Secondary Diffuse Bounces to 1.

  14. In the Outliner, expand the Car group. Select the leftBody, and Ctrl+click the rightBody. Open the Hypershade and assign the metal shader to these two groups. Create another test render (Figure 9.30).

    The white polygon is reflected in the surface of the car. The shader that is applied to the body is a very simple Phong-type shader, and it looks pretty good.

  15. Save the scene as car_v05.ma. To see a version of the scene to this point, open the car_v05.ma scene from the chapter9scenes directory on the DVD.

Apply a reflective material to the body, enhancing the realism of the lighting.

Figure 9.30. Apply a reflective material to the body, enhancing the realism of the lighting.

Final Gathering Maps

Setting the Rebuild option to Off causes mental ray to reuse any saved Final Gathering maps generated from previous renders. This saves a great deal of time when creating a final render. However, if the camera is moving and Final Gathering requires additional points for interpolation, new points are generated and appended to the saved map.

When Rebuild is set to Freeze, the scene is rendered with no changes to the Final Gathering map regardless of whether the scene requires additional points. This reduces flickering in animated sequences, but you need to make sure the scene has enough Final Gathering points generated before using the Freeze option.

If a scene has an animated camera, you can generate the Final Gathering map by rendering an initial frame with Rebuild set to On and moving the Time slider until the camera is in a new position, then setting Rebuild to Off and rendering again. Repeat this procedure until the path visible from the camera has been sufficiently covered with Final Gathering points. Then create the final render sequence with Rebuild set to Freeze. This short exercise demonstrates this technique.

  1. Open the car_v06.ma scene from the chapter9scenes directory on the DVD. In this scene, a camera named FGCam is animated around the car.

    The first 10 frames of the animation have been rendered using Final Gathering. In the Final Gathering Map section of the Render Settings window, the Rebuild attribute is set to On, so new Final Gathering points are calculated with each frame.

  2. View the rendered sequence by choosing File

    Neon Lights
  3. In the Final Gathering Map section, turn on Enable Map Visualizer. Set the timeline to frame 1, and create a test render using the FGCam camera.

  4. When the render is complete, switch to the perspective view. In the viewport window, disable NURBS Surfaces and disable Polygons in the View menu. You can clearly see the Final Gathering points outlining the surface of the car.

    Notice there are no points on the surfaces that have the metal texture applied. This is because they are reflective surfaces with a very low diffuse value—remember that Final Gathering is used for rendering diffuse surfaces, such as the surfaces with the white Lambert shader applied (see Figure 9.31).

  5. In the Render Settings window, set Rebuild to Off. Set the timeline to 4, and create another test render using the FGCam camera.

    The Final Gather points are visible in the scene after creating a test render.

    Figure 9.31. The Final Gather points are visible in the scene after creating a test render.

    You'll notice it takes less time to render, and the display of the Final Gathering points in the perspective view is updated. More points have been added to correspond with the FGCam's location on frame 4. The Final Gathering points are saved in a file named default.fgmap.

  6. Make three more test renders from frames 6, 8, and 10.

  7. Render a sequence of the first 10 frames of the animation, and compare this to the carFG_test1 sequence. You can also view the carFG_test2 sequence in the chapter9images directory on the DVD.

    The flickering in the new sequence is greatly reduced using this technique.

  8. Save the scene as car_v07.ma. To see a version of the sequence, open the car_v07.ma scene from the chapter9scenes directory on the DVD (see Figure 9.32).

This system does not work if there are animated objects in the scene. If the Final Gathering map is generated and saved while an object is in one position, the same irradiance values are used on a subsequent frame after the object has moved to a new position. This can lead to a strange result. You can enable the Optimize For Animations option in the Final Gathering Tracing section to help reduce Final Gathering flickering in scenes with animated objects.

Additional Final Gathering points are added to the existing map file each time a test render is created.

Figure 9.32. Additional Final Gathering points are added to the existing map file each time a test render is created.

The Diagnose Final Gathering option color codes the Final Gathering points so you can easily distinguish the initial points created with the first render from points added during subsequent renders.

Other Final Gathering quality controls are found in the Final Gathering Quality and Final Gathering Tracing sections in the Indirect Lighting tab of the Render Settings window.

Optimize For Animations

This option essentially automates the system described previously. It reduces flickering but at the expense of accuracy.

Use Radius Quality Control

This setting has been largely replaced by the Point Interpolation setting. However, it can still be used if you prefer. If this option is enabled, the Point Interpolation setting is automatically disabled and vice versa. Use Radius Quality Control corresponds to the Accuracy setting. It basically sets the sampling range for Final Gathering rays to search for irradiance information from nearby surfaces. The typical practice is to set Max Radius to 10 percent of the overall scene size and Min Radius to 10 percent of Max Radius. You also have the option of specifying the radius in terms of pixel size. These settings help to reduce artifacts.

Filter

This attribute relates to using High Dynamic Range (HDR) images and will be discussed in Chapter 10.

Falloff Start and Stop

These settings limit the distance Final Gathering rays can travel. This is especially important in a large scene where objects may be far apart. You can optimize render time by setting a range for these values. When a Final Gathering ray has reached its maximum distance as set by Falloff Max, it samples any further irradiance and color values from the environment and uses them to shade the surface. The falloff start begins a linear transition to the environment sampling, and the falloff stop is the end point for this transition as well as the farthest point a Final Gathering ray can travel. Think of the start and stop points as the beginning and end of a gradient. At the start portion of the gradient, surface sampling is at 100 percent and environment sampling is at 0 percent. At the stop point of the gradient, the surface sampling is at 0 percent and the environment sampling is at 100 percent.

This can reduce render times even in an indoor scene. By default the scene background color is black. If you set Falloff Start to 15 and Falloff Stop to 20 and render, the frame takes less time to render but comes out very dark in shadowed areas that are 15 to 20 units from a Final Gathering point. This is because the default black background is being blended into the surface color. If you feel too much detail is lost to the darkness, you can create an environment dome with a constant color or an HDR image, or you can simply set the render camera's background to a value above 0. Setting the value too high reduces contrast in the scene, similar to adding an ambient light. A low value between 0.25 and 0.5 should work well.

Reflections, Refractions, and Max Trace

These sliders set the maximum number of times a Final Gathering ray can be reflected (create a secondary ray) or refracted from reflective, glossy, or transparent surfaces. The default values are usually sufficient for most scenes.

Using Lights with Final Gathering

The previous exercises demonstrated how Final Gathering can render a scene without lights by using only incandescent objects. However, for many situations you'll want to combine Final Gathering with lights so that specular highlights and clear shadows are visible in the render. If you take a look outside on a sunny day, you'll see examples of direct lighting, cast shadows, indirect lighting, and ambient occlusion working together. Likewise, a typical photographer's studio combines bright lights, flash bulbs, and diffuse lights to create a harmonious composition. You'll also find that combining lights and Final Gathering produces a higher-quality render. In the car_v08.ma scene found in the chapter9scenes directory on the DVD, light-emitting planes are used as fill lights in conjunction with a shadow-casting spotlight (Figure 9.33).

In many cases the look of indirect lighting can be improved and rendering times can be reduced by using Final Gathering and Global Illumination at the same time. Final Gathering usually works fairly well on its own, but Global Illumination almost always needs a little help from Final Gathering to create a good-looking render. When Global Illumination and Final Gathering are enabled together, the Final Gathering secondary diffuse bounce feature no longer affects the scene; all secondary diffuse light bounces are handled by Global Illumination.

A spotlight is combined with light-emitting planes and rendered using Final Gathering.

Figure 9.33. A spotlight is combined with light-emitting planes and rendered using Final Gathering.

Image-Based Lighting

Image-Based Lighting (IBL) uses the color values of an image to light a scene. This can often be done without the help of additional lights in the scene. When you enable IBL, you have the choice of rendering the scene using Final Gathering, IBL with Global Illumination, or IBL with the mental ray Light Shader. This section will describe all three methods.

You can use both High Dynamic Range (HDR) images and Low Dynamic Range (LDR) images with IBL. HDR differs from LDR in the number of exposure levels stored in the format. An LDR image is typically a standard 8-bit or 16-bit image file, such as a TIFF. An HDR image is a 32-bit floating point format image that stores multiple levels of exposure within a single image. Both 8-bit and 16-bit image formats store their color values as integers (whole numbers), while a 32-bit floating point file can store colors as fractional values (numbers with a decimal). This means that the 8-bit and 16-bit formats cannot display a full range of luminance values, whereas the 32-bit floating point images can. Multiple levels of exposure are available in HDR 32-bit floating images, which can be used to create more dynamic and realistic lighting in your renders when you use IBL.

HDR images come in several formats including .hdr, OpenEXR (.exr), Floating Point TIFFs, and Direct Draw Surface (DDS). Most often you'll use the .hdr and .exr image formats when working with IBL.

When an HDR image is used with IBL, the lighting in the scene looks much more realistic, utilizing the full dynamic range of lighting available in the real world. When integrating CG into live-action shots, a production team often takes multiple HDR images of the set and then uses these images with IBL when rendering the CG elements. This helps the CG elements to match perfectly with the live-action shots.

The downside of HDR images is that they require a lot of setup to create. However, you can download and use HDR images from several websites, including Paul Debevec's website (www.debevec.org/Probes/). Paul Debevec is a pioneer in the field of computer graphics and virtual lighting. He is currently a researcher at the University of Southern California's Institute for Creative Technologies.

Several companies, such as Dosch Design (www.doschdesign.com/), sell packages of HDRI images on DVD, which are very high quality.

HDR images are available in several styles including angular (light probe), longitude/latitude (spherical), and vertical cubic cross. mental ray supports angular and spherical. You can convert one style to another using a program like HDRShop.

Enabling IBL

To use IBL in a scene, open the Render Settings window, and make sure mental ray is chosen as the renderer. Switch to the Indirect Lighting tab, and click the Image Based Lighting Create button at the top of the window. This creates all the nodes you need in the scene to use IBL.

You can have more than one IBL node in a scene, but only one can be used to create the lighting.

IBL and Final Gathering

Using IBL with Final Gathering is similar to the concept of using light-emitting objects. When you enable IBL, a sphere is created, and you can map either an HDR or a LDR image to the sphere (HDR is the most common choice). The scene is rendered with Final Gathering enabled, and the luminance values of the image mapped to the sphere are used to create the lighting in the scene. You can use additional lights to create cast shadows and specular highlights or use IBL by itself. The following exercise takes you through the process of setting up this scenario.

  1. Open the car_v09.ma scene from the chapter9scenes directory on the DVD.

  2. Open the Render Settings window, and make sure the Render Using option is set to mental ray.

  3. Switch to the Indirect Lighting tab, and click the Create button next to Image Based Lighting. This creates the mentalrayIbl1 node, which is a sphere scaled to fit the contents of the scene.

  4. Select the mentalrayIbl1 node in the Outliner, and open its Attribute Editor. Click the folder icon next to the Image Name field. Go to www.debevec.org/Probes/ and download the building_probe.hdr image to the sourceimages directory of the current project. Connect this image to the mentalrayIbl node in the scene.

    This image was downloaded from Paul Debevec's website, where you can find many other examples of HDR images.

  5. The image is in the Angular mapping style, so set Mapping to Angular.

  6. In the Render Settings window, enable Final Gathering. Create a test render using the renderCam camera.

    In this case you'll see that the image is blown out. You can also see the HDR image in the background of the scene.

  7. In the Attribute Editor for the mentalrayIblShape1 node, scroll down to Render Stats. Turn off Primary Visibility.

  8. Enable Adjust Final Gathering Color Effects. This enables the Color Gain and Color Offset sliders. Set the Color Gain slider to a light gray.

  9. Create another test render (Figure 9.34).

  10. Save the scene as car_v10IBL_FG.ma. To see a version of the scene, open the car_v10IBL_FG.ma scene in the chapter9scenes folder on the DVD.

The settings on the mentalrayIblShape1 node are adjusted in the Attribute Editor. The scene is lit using the HDR image and Final Gathering.

Figure 9.34. The settings on the mentalrayIblShape1 node are adjusted in the Attribute Editor. The scene is lit using the HDR image and Final Gathering.

You can see the car is now lit entirely by the HDR image. The HDR image is also visible in the reflection on the surface of the car. If you want to disable the visibility of the reflections, turn off Visible As Environment.

If you need to adjust the size and position of the IBL sphere, turn off the Infinite option at the top of the node's Attribute Editor.

The quality of the lighting can be adjusted using the Final Gathering controls in the Render Settings window.

IBL and Global Illumination

The IBL node can be used to emit photons into the scene, both Global Illumination and Caustics. This can be used in conjunction with Final Gathering or with Global Illumination alone.

  1. Open the car_v09.ma scene from the chapter9scenes directory on the DVD.

  2. Follow steps 2 through 5 in the "IBL and Final Gathering" section to set up the IBL node.

  3. In the Render Settings window, enable Global Illumination.

  4. In the mentalrayIbl1 node, under Photon Emission, enable Emit Photons. Turn off Primary Visibility in the Render Stats section. Create a test render from the scene.

  5. The render most likely looks very blown out. In the mentalrayIbl1 node's Attribute Editor, enable Adjust Photon Emission Color Effects and set Color Gain to a light gray color.

  6. Increase the Global Illumination value to 150000 Photons, and set Accuracy in the Render Settings window to 1200. Create a test render (Figure 9.35).

  7. Save the scene as car_v10IBL_GI.ma. To see a version of the scene, open the car_v10IBL_GI.ma scene in the chapter9scenes folder on the DVD.

The render looks pretty good, but you'll get better results combining Global Illumination with either Final Gathering or the IBL Light Shader. You can also turn on Caustics in the Render Settings window if you want create caustic light effects from a surface reflecting the IBL.

You can use the Global Illumination settings in the Render Settings window as well as the Photon Emission settings in the mentalrayIb1 node to tune the look of the photons. By default, photons emitted from the IBL node are stored in the map at the moment they hit a surface. This makes the Global Illumination render fast and works well if Global Illumination is used by itself.

The IBL node emits photons into a scene rendered using Global Illumination.

Figure 9.35. The IBL node emits photons into a scene rendered using Global Illumination.

If you are using the IBL node to emit light (covered in the next section) or you are emitting caustic photons alone, turn on Standard Emission.

The Adjust Photon Emission Color Effects option allows you to adjust the brightness of the IBL's photon emission using the Color Gain and Color Offset sliders.

IBL Light Shader

When the Emit Light option is enabled in the mentalrayIbl1 node, the image used for the IBL node emits light as if the image itself were made up of directional lights. Each directional light gets a color value based on a sampling taken from the image mapped to the sphere. This technique tends to work best with images that have large areas of dark colors.

  1. Open the car_v09.ma scene from the chapter9scenes directory on the DVD.

  2. Follow steps 2 through 5 in the "IBL and Final Gathering" section to set up the IBL node.

  3. In the Attribute Editor for the mentalrayIbl1 node, turn on Emit Light in the Light Emission rollout.

  4. Turn on Adjust Light Emission Color Effects, and set the Color Gain value to a dark gray. Create a test render of the scene. The render will take a while to create (15 minutes on my machine), but it should look pretty good (Figure 9.36).

  5. Save the scene as car_v10IBL_LS.ma. To see a version of the scene, open the car_v10IBL_LS.ma scene in the chapter9scenes folder on the DVD.

The Quality U and Quality V sliders adjust the sampling of the image. Higher values increase precision but add to render time. The image mapped to the IBL is converted into a control texture by the shader. Every pixel in the control texture is converted to a directional light. The Quality sliders control the resolution of the control texture.

The IBL node acts as a series of directional lights that sample their color values from the HDR image.

Figure 9.36. The IBL node acts as a series of directional lights that sample their color values from the HDR image.

To optimize render times, the light shader node samples the image and assigns a certain number of lights as key lights based on the color values of the image. The other parts of the image are randomly sampled and used as fill lights. This saves mental ray time because it does not need to use every single light created by the control texture, which would make rendering prohibitively slow. The values in the Samples field represent the number of key lights (first value) and fill lights (second value) used during rendering.

The Low Samples setting is used when both Emit Light and Final Gathering are used in combination. This value specifies the number of samples taken when using Final Gathering. By default it is set to 1/8 the Samples setting.

The Vary Focus setting randomly alters the rotation of each directional light, which can improve quality.

The Disable Back Lighting option should be used when the scene does not need backlighting to create subsurface scattering effects. Leaving this option on optimizes sampling of the scene.

To get the best-quality rendering using IBL, it's probably a good idea to combine methods for rendering the image. Use both Emit Light and Final Gathering (Figure 9.37), or use Final Gathering with Global Illumination. In many cases you may need to lower the Color Gain value of the image to keep the lighting from appearing blown out.

The IBL is used with both the light shader and Final Gathering.

Figure 9.37. The IBL is used with both the light shader and Final Gathering.

Physical Sun and Sky

mental ray provides a special network of lights and shaders that can accurately emulate the look of sunlight for outdoor scenes. Using the Physical Sun and Sky network requires rendering with Final Gathering. It's very easy to set up and use.

Enable Physical Sun and Sky

To create the Physical Sun and Sky network, use the controls in the Indirect Lighting tab of the Render Settings window.

  1. Open the car_v10.ma scene from the chapter9scenes directory on the DVD.

  2. Open the Render Settings window and make sure Render Using is set to mental ray.

  3. Switch to the Indirect Lighting tab in the Render Settings window, and click the Create button for Physical Sun And Sky.

    Clicking the Create button creates a network of nodes that generates the look of sunlight. These include the mia_physicalsun, mia_physicalsky, and mia_exposure simple nodes. You'll notice that there is a directional light named sunDirection that has been added to the scene. To control the lighting of the scene you'll change the orientation of the light. The other light attributes (position, scale, intensity, color, and so on) will not affect the lighting of the scene. To change the lighting you need to edit the mia_physicalsky node in the Attribute Editor.

  4. Select the sunDirection light in the Outliner, and use the Move tool to raise it up in the scene so you can see it clearly. The position of the sun will not change the lighting in the scene.

  5. In the Render Settings window, make sure Final Gathering is enabled. It should be turned on by default when you create the physical sun nodes.

  6. Open the Render View window, and create a test render from the renderCam camera. Store the rendered image in the Render View window.

    The rendered image includes cast shadows from the sun, ambient occlusion created by Final Gathering, and a sky gradient in the background that is reflected in the body of the car.

  7. Select the sunDirection light, and set its Rotate X value to −150. Create another test render and compare it with the first.

    When you change the orientation of the sunDirection light, it affects the color of the lighting as well to accurately simulate the lighting you see at different times of day.

  8. Select the sunDirection node, and use the following settings:

    • Rotate X: 329

    • Rotate Y: 12

    • Rotate Z: −51.8

      Create another test render. With these settings the sun itself is actually visible in the sky (see Figure 9.38).

  9. Save the scene as car_v11.ma. To see a finished version of the scene, open the car_v11.ma scene from the chapter9scenes directory on the DVD.

Changing the rotation of the sunDirection light changes the lighting to emulate different times of the day.

Figure 9.38. Changing the rotation of the sunDirection light changes the lighting to emulate different times of the day.

Editing the Sky Settings

To change the look of the sky in the scene, use the settings found on the mia_physicalsky node.

A number of settings in the Attribute Editor for the sunDirection node help define the color and quality of the sky and the sun in the render. Here is a brief description of some of these settings (Figure 9.39):

Multiplier

This setting adjusts the overall brightness of the sky.

R, G, and B Unit Conversions

These setting adjust the coloring of the sky in the R (red), G (green), and B (blue) channels when these values are changed incrementally.

Haze

This setting adds haziness to the sky.

Red/Blue Shift

Use this option to shift between warm and cool lighting in a scene. Negative numbers shift colors toward blue; positive numbers shift colors toward red. The value range should be kept between −1 and 1.

Horizon Height and Blur

These settings change the position and blurriness of the horizon line visible in the renders behind the geometry.

Ground Color

This option changes the color of the area below the horizon. Note that the horizon does appear in reflective shaders applied to the geometry in the scene.

Night Color

This option affects the color of the sky when the sun is rotated close to 180 degrees.

Sun Direction

This setting rotates the sunDirection light in the scene to change the sun direction. Fields should be left at 0.

Sun

This option connects the sun settings to a different light in the scene.

Sun Disk Intensity, Sun Disk Scale, and Sun Glow Intensity

These settings affect the look of the sun when it is visible in the render.

Use Background

This option adds a texture for the environment background. Use this setting as opposed to the standard Maya environment shaders.

The settings for changing the look of the physical sky in the render

Figure 9.39. The settings for changing the look of the physical sky in the render

Update Camera Connections

This button adds a new renderable camera to the scene after you create the Physical Sun and Sky network. The network applies specific shaders to all of the renderable cameras in the scene when it is first created. Any new cameras added to the scene will not have these connections enabled by default.

Remove Camera Connections

This option removes all cameras from the Physical Sun and Sky network.

If you need to delete the Physical Sun and Sky network from the scene, open the Render Settings window, and click the Delete button for the Physical Sun and Sky attribute.

mental ray Area Lights

mental ray area lights are designed to create a simulation of light sources in the real world. Most lights in Maya emit light rays from an infinitely small point in space. In the real world, light sources are three-dimensional objects, such as a light bulb or a window, that have a defined size.

Lighting a scene using standard lights, such as the point and spot lights, often require additional fill lighting to compensate for the fact that these lights do not behave like real-world light sources. Area lights are designed as an alternative to this approach. A mental ray area light is essentially an array of spot lights. The array creates a 3D light source, which results in more realistic light behaviors, especially with regard to shadow casting. The downside is that area lights often take longer to render, so they are not always ideal for every situation.

Using Area Lights

Follow the steps in this exercise to understand how to use area lights in mental ray:

  1. Open the crystalGlobe_v01.ma scene from the chapter9scenes directory on the DVD.

  2. Create an area light (Create

    Using Area Lights
    • Translate X: −2.848

    • Translate Y: 4.826

    • Translate Z: 0.745

    • Rotate X: −33.259

    • Rotate Y: −90

    • Rotate Z: 0

    • Scale X: 2.5

    • Scale Y: 2.5

    • Scale Z: 2.5

  3. In the Attribute Editor, enable Use Ray Trace Shadows in the light's Shadows rollout.

  4. Open the Render Settings window, and set Render Using to mental ray. In the Quality tab, set the Quality Presets option to Production.

  5. Open the Render View window, and create a test render from the renderCam camera. Store the image in the render view.

    The render looks very blown out and grainy. As you know, you can reduce the grainy quality by increasing the shadow rays used on the light. However, there is something important and potentially confusing about using a standard Maya area light with mental ray. The light as it stands right now is not actually taking advantage of mental ray area light properties. To make the light a true mental ray area light, you need to enable the Use Light Shape attribute in the Attribute Editor. Until you enable this attribute, you'll have a hard time getting the area light to look realistic.

  6. Open the Attribute Editor for areaLight1. Switch to the AreaLightShape1 tab. In the mental ray

    Using Area Lights

    The new render is less blown out, and the shadows are much softer (although still grainy).

  7. To brighten the light, set Intensity to 2; create another test render (see Figure 9.40).

    The mental ray area light is enabled when Use Light Shape is activated in the Attribute Editor.

    Figure 9.40. The mental ray area light is enabled when Use Light Shape is activated in the Attribute Editor.

    Unlike Maya area lights, the intensity of mental ray area lights is not affected by the scale of the light. To change the intensity, use the Intensity slider at the top of the Attribute Editor. The shape of the shadows cast by mental ray area lights is affected by the shape chosen in the Type menu and the scale of the light.

    You can make the light visible as a light source in the scene by choosing the Visible option.

    To improve the quality of the shadows, increase the High Samples setting. The High Samples and Low Samples settings control the quality of the shadow in reflected surfaces. These can be left at a low value to improve render efficiency.

  8. Set Light Shape Type to Sphere, and increase High Samples to 32. Scale the light down to 0.6 in X, Y, and Z, and turn on the Visible option.

  9. Create a test render, and compare the render to the previous versions (Figure 9.41).

    A standard Maya spotlight can also be converted into a mental ray area light.

  10. Scroll up in the Attribute Editor for areaLight1, and set the light Type to Spotlight. Set Cone Angle to 60.

  11. Scroll down to the mental ray section. Notice that Area Light is still activated. In the scene you can see that the area light is attached to the spotlight. It may be still set to the sphere type.

    The area light is visible in the render.

    Figure 9.41. The area light is visible in the render.

  12. There are now two fields available for High Samples and Low Samples. These represent the distribution of samples in U and V space within the area light shape. Set both High Samples to 8.

  13. Create another test render (Figure 9.42).

    The light quality and shadow shape remain the same as in the previous renders. However, switching the light Type to Spotlight adds the penumbra shape you expect from a spotlight. This allows you to combine the properties of spotlights and mental ray area lights. The Visible option in the mental ray settings does not work when using a spotlight as the original light.

    The shape of the spotlight creates shadows based on the area light settings.

    Figure 9.42. The shape of the spotlight creates shadows based on the area light settings.

    Spotlights and area lights are the only kinds of lights that can be converted to mental ray area lights. In older versions of Maya, point lights also had this ability.

  14. Save the scene as crystalGlobe_v03.ma. To see a version of the scene, open the crystalGlobe_v03.ma scene from the chapter 9scenes directory on the DVD.

Light Shaders

mental ray has a number of light shaders that can be applied to lights in a scene. The purpose of these shaders is to extend the capabilities of Maya lights to allow for more lighting options. When a mental ray shader is applied to a Maya light, specific attributes on the original light node are overridden. The light's attributes can then be set using the controls on the light shader node.

Some shaders, such as the Mib_blackbody and Mib_cie_d shaders, are very simple. These two shaders translate the color of the light as temperature specified in Kelvin. Other shaders are more complex, providing a number of attributes that can be used in special circumstances.

This section will discuss some of the light shaders and how they can be used in Maya scenes.

Physical Light Shader

The Physical Light shader is used primarily with indirect lighting (Final Gathering, Global Illumination) to create more physically accurate light behavior. There are also certain materials, such as the mental ray Architectural materials (mia), that are designed to work with physical lights. Physical lights always cast ray trace shadows, and the falloff rate for the light obeys the inverse square law just like lights in the real world. This law states that the intensity of light is inversely proportional to the square of the distance from the source. So the light intensity decreases rapidly as the light travels from the source.

Physical lights are easy to set up and use. Once you are comfortable with them, consider using them whenever you use indirect lighting, such as Global Illumination and Final Gathering. This exercise will show you how to create a physical light.

  1. Open the rotunda_v01.ma scene from the chapter9scenes directory on the DVD.

  2. Create a point light, and position it using these settings:

    • Translate X: 0

    • Translate Y: 52

    • Translate Z: 26

  3. Open the Attribute Editor for the point light, and switch to the pointLightShape1 tab. Scroll down, and expand the mental ray settings.

  4. Expand the Custom Shaders rollout. Click on the checkered box to the right of the Light Shader field. From the Create Render Node pop-up, switch to the mental ray tab and expand the MentalRay Lights section. Click the Physical_light icon to add the Physical Light shader (Figure 9.43).

  5. Click the physical_light1 tab in the Attribute Editor. Click on the color swatch next to the Color settings. The Color Chooser appears. You'll notice that the value is set to 1000 by default. This value represents the intensity of the light; set this value to 10000.

  6. Create a test render from the renderCam camera (see Figure 9.44). Store the render in the Render View window.

    Apply the Physical Light shader to the point light.

    Figure 9.43. Apply the Physical Light shader to the point light.

    Render the scene using a physical light.

    Figure 9.44. Render the scene using a physical light.

    The Cone setting is used when the Physical Light shader is applied to mental ray spot and area spotlights to define the cone angle and penumbra.

    The Threshold setting defines a minimum illumination value. When you increase the threshold, the lighting in the scene is contracted around the brighter areas, giving you more control over the precise areas of light in the scene.

    The Cosine Exponent attribute is similar to the Cone setting and works only when the shader is applied to mental ray area lights. It contracts the area of light cast when this shader is applied to mental ray area lights. As value of Cosine Exponent increases, the light cast by the area light becomes more focused.

    You can see in the test render that, even though shadows are not enabled for the light, ray trace shadows are cast in the scene.

  7. Switch to the pointLightShape1 tab, and enable Emit Photons. Set Photon Intensity to 25000.

  8. In the Render Settings window, enable Global Illumination and Final Gathering. Create another test render, and compare it to the render stored in the Render View window (Figure 9.45).

    Physical Light shaders create realistic lighting and work well with Final Gathering and Global Illumination.

    Figure 9.45. Physical Light shaders create realistic lighting and work well with Final Gathering and Global Illumination.

Photometric Lights and Profiles

Photometric lights allow you to attach light profiles created by light manufacturers so you can simulate specific lights in your scenes. These profiles are often available on light manufacturers' websites. The profile itself is a text file in the .ies format.

The profiles simulate the qualities of the light, such as falloff, and the influence of the light fixture. A light profile can include the sconces and fixtures attached to the light itself. This is most helpful in creating accurate architectural renderings.

To use a photometric light, you can attach the Pmib_light_photometric shader to a point light and then attach the profile to the light using the Profile field in the shader's attributes. You can also skip using the shader altogether and attach the .ies profile directly to the point light in the Light Profile field available in point lights.

In many cases, you'll need to adjust the shadows cast by lights using a profile to make them more realistic. Use ray trace shadows and adjust the Shadow Rays and Light Radius values to improve the look of the shadows.

If you'd like to experiment using light profiles, you can download .ies format light profiles from www.lsi-industries.com/products.asp.

Portal Light

The purpose of the Portal Light shader is to correct for common problems encountered when rendering a scene in which the light is entering a room from the outside through a window or opening. Oftentimes, when rendering such a scene without the Portal Light shader, the number of Final Gathering rays emitted by the camera needs to be very high so they can find the light entering the room from the window. The Portal Light shader helps focus the Final Gathering rays on the opening itself, so fewer rays need to be used and render time can be more reasonable.

This exercise will demonstrate how to use the Portal Light shader.

  1. Open the temple_v07.ma scene from the chapter9scenes directory in the DVD.

    In this version of the scene a Physical Sun and Sky network has been added. The sunDirection light is oriented so the sunlight enters the temple through the window on the far side. Final Gathering, which is normally on when the Physical Sun and Sky network is created, is disabled.

  2. Create a test render from the renderCam camera, and store the render in the Render View window.

    In this render, you can see the light coming through the window, casting shadows on the floor. The light has a slight amber quality; notice that the sky in the window is a cool blue. These colors are based on the orientation of the light, which simulates a late afternoon or early morning type of lighting.

  3. Open the Render Settings window, and enable Final Gathering. Use the default Accuracy of 250 and a Point Density of 0.8. Create another test render (Figure 9.46).

    The lighting in the scene is very dark and blotchy. It can be improved by increasing the accuracy and the scale but at the cost of render time. The Final Gathering points emitted by the rendering camera are not being used efficiently. The next step is to set up an area light that uses the Portal Light shader. This shader works only with mental ray area lights (or spotlights that have Area Light activated in the mental ray section of the Attribute Editor).

    Even with Final Gathering enabled, the render is very dark, and there is significant noise.

    Figure 9.46. Even with Final Gathering enabled, the render is very dark, and there is significant noise.

  4. Create an area light, and position it in front of the window—on the inside. Use the following settings in the Channel Box:

    • Translate X: 0

    • Translate Y: 19.63

    • Translate Z: −11.194

    • Rotate X: 180

    • Rotate Y: 0

    • Rotate Z: 0

    • Scale X: 2.88

    • Scale Y: 2.88

    • Scale Z: 2.88

  5. Open the Attribute Editor for the area light. In the mental ray section, turn on Use Light Shape and activate the Visible option.

    The visibility of the area light must be enabled in these options for the Portal Light shader to work. The actual visibility of the light can be controlled in the shader's attributes once it has been applied to the light.

  6. Scroll down to the Custom Shaders rollout. Click on the checkered box to the right of the Light Shader field. In the Create Render Node pop-up, switch to the mental ray tab, and click on the Mia_portal_light shader.

  7. The Create Render Node window closes, and the Attribute Editor switches to the mia_portal_light1 tab. Select areaLight1 in the Outliner to switch the Attribute Editor back to the area light settings.

  8. Scroll down to the Custom Shaders section. In the Photon Emitter field type mia_portal_light1, and hit the Enter key (Figure 9.47). Both the Light Shader and Photon Emitter attributes must be connected to the Portal Light shader; otherwise it will not work. This is true even if the light does not emit photons.

    Connect the mia_portal_light1 shader to both Light Shader and Photon Emitter in the area light's Attribute Editor.

    Figure 9.47. Connect the mia_portal_light1 shader to both Light Shader and Photon Emitter in the area light's Attribute Editor.

    Notice that shadows were not enabled for the area light. Shadows, intensity, and the visibility of the area light are now controlled by the settings in the mia_portal_light1 tab.

  9. In the Render Settings window, switch to the Indirect Lighting tab. Disable both Final Gathering and Global Illumination. Create another test render. Compare this render with the one created in step 2.

    You'll see more of the light coming through the window, the cool coloring of the sky, and the amber color of the bounced light on the walls. However, if indirect lighting is disabled, where is the bounced light coming from? The shader is using the area light to intensify the light (and the colors of the light) coming from the physical sun and sky seen outside the window. The shader makes the area light block Final Gathering points from going outside the window and converts the light outside the window (created by the Physical Sun and Sky network) into direct light.

  10. In the mia_portal_light1 tab of the Attribute Editor, set Intensity Multiplier to 5. Create another test render (Figure 9.48, top-right image).

    The higher intensity increases the light coming through the window.

  11. In the Render Settings window, enable Final Gathering and set Secondary Diffuse Bounces to 3. Create another test render (Figure 9.48, lower-left image).

    The lighting in the temple is significantly brighter. To help smooth the noise of the temple walls, enable Global Illumination. Note that when you enable Global Illumination, the Secondary Bounce setting in the Final Gathering Settings section no longer affects the lighting of the scene. Global Illumination takes care of light bounces in the scene.

  12. In the Render Settings window, enable Global Illumination.

  13. Click the areaLight1 node and enable Emit Photons. Set Photon Intensity to 20000 and the number of Global Illum Photons to 15000 (lower-right image, Figure 9.48).

    The noise pattern on the walls is decreased, and the render takes several minutes less to complete. The render itself can be improved by increasing Accuracy on the Final Gathering Settings. Try turning off the Enable Sky Portal option in the mia_portal_light1 node's Attribute Editor, and create a test render using the same settings. You can clearly see how the sky portal shader helps boost the lighting of the room and reduce the amount of noise in the indirect lighting.

    The upper-left image shows the lighting without the portal shader applied. The portal shader boosts the light coming in from the window (upper right). The lower-left image shows the portal light with Final Gathering. The lower-right image shows the portal light with both Final Gathering and Global Illumination.

    Figure 9.48. The upper-left image shows the lighting without the portal shader applied. The portal shader boosts the light coming in from the window (upper right). The lower-left image shows the portal light with Final Gathering. The lower-right image shows the portal light with both Final Gathering and Global Illumination.

    Here is a brief description of some of the other settings available on the Portal Light shader:

    Intensity Multiplier

    This setting controls the intensity of the portal light.

    Color Multiplier

    This adjusts the color of the portal light. Remember that the color of the portal light is also affected by the colors of the lights coming through the window (colors created by physical sun and sky shaders, IBL, light cards, and so on).

    Transparency

    This slider acts as a multiplier for the color of the light transmitted by the area light. Adjusting the Transparency slider reduces the blown-out quality of the light as well as adjusts the color of the light.

    Shadows

    The option turns shadow casting on or off for the area light. This overrides the Shadow Casting setting on the area light node.

    Shadow Ray Extension

    This setting determines where shadow casting starts for the light. If this value is 0, shadow casting starts at the location of the area light. If it is a positive value, shadow casting starts behind the area light as if the shadow starts outside the window.

    Emit Direct Photons

    This option turns off the direct light properties of the portal light. In this case the light emits photons but no direct light.

    Use Custom Environment

    This option uses colors from a specified environment shader. When this setting is off, the shader takes colors from the environment outside the window.

    Visible

    This setting enables the visibility of the area light itself. This overrides the visibility setting in the area light's Attribute Editor.

    Look Up Using FG Rays

    Enable this setting when using the physical sky shader to color the environment of the scene.

    Portal Shader

    Use this option with IBL as well as light cards placed outside the window. If the area light is placed outside the window, an increase in graininess may result.

  14. Save the scene as temple_v08.ma. To see a version of the scene, open the temple_v08.ma scene from the chapter9scenes directory on the DVD.

Participating Media

Participating Media (PM) refers to the phenomenon of light reflecting off particulate matter suspended in air. This is also known as volumetric lighting. mental ray has the ability to simulate extremely realistic participating media effects. These techniques are processor intensive, so you should use them wisely to avoid extremely long render times.

The setup for creating PM light effects involves a number of nodes and takes a little practice to get used to. This exercise demonstrates how to create a basic PM light rig.

  1. Open the temple_v09.ma scene from the chapter9scenes directory on the DVD.

  2. Create a directional light, and place it outside the window of the temple (even though the location of the light doesn't matter for directional lights, placing it outside the window helps you visualize where the light is coming from).

  3. Set the Rotate X value of the light to −150.

  4. Open the Attribute Editor for directionalLight1, and switch to the directionalLightShape1 tab. Expand the mental ray section and, in the Custom Shaders section, click on the checkered box to the right of the Light Shader field.

  5. In the Create Render Nodes window, switch to the mental ray tab. Under MentalRay Lights, click the Physical_light button to apply a Physical Light shader to the directional light.

  6. Switch to the physical_light1 tab, and click on the color swatch. The Color Chooser opens up. By default, Value is set to 1000, which works well with point, area, and spotlights but is too high for directional lights. Set this value to 10.

    The PM effect needs a defined volume within which it can create the medium for the volumetric light. To create this you can use a polygon cube.

  7. Switch to the perspective view. Create a polygon cube. Scale it up so it encompasses the entire structure and the light (Figure 9.49). Name the cube volumeCube.

  8. Open the Hypershade window. Switch to the Create mental ray Nodes tab. From the Materials section, choose the Transmat material. The Transmat material is essentially a transparent material that disables the visibility of connected surfaces in the render. To create the Participating Media, apply this material to the surface that contains the volumetric light.

    Create a cube and scale it so it fits around the geometry of the scene.

    Figure 9.49. Create a cube and scale it so it fits around the geometry of the scene.

  9. Apply the Transmat material to the volumeCube (select the volumeCube, and in the Hypershade, right-click on the transmat1 material and choose Assign transmat1SG To Selection).

  10. Open the Attribute Editor for the volumeCube. In the Render stats, turn off the Casts Shadows and Receive Shadows options.

    The Transmat material causes the cube to be invisible. However, unless you turn off the Casts Shadows and Receive Shadows options, the cube will block the physical light from entering the scene (this is because the light is a directional light, and as you saw before, the position of the directional light has no bearing on how it casts light, only its rotation; even when the light is inside the cube, the surface of the cube can still cast shadows and block the light).

    You'll notice that the Transmat material has no options. The volumetric shader is actually applied to the shader group node connected to the Transmat material. This is often the case with mental ray shaders, as you'll see in Chapter 10.

  11. In the Hypershade, select the Transmat material and display the upstream and downstream connections.

  12. From the Create mental ray Nodes section, expand the Volumetric Materials rollout, and click the parti_volume node to create the volumetric shader.

  13. Open the Attribute Editor for the transmat1SG node. Expand the mental ray section, and MMB-drag the parti_volume1 node from the Hypershade Work Area into the slot for the Volume Shader in the Custom Shaders section. This connects it to the Transmat material's shading group (Figure 9.48).

  14. Open the Attribute Editor for the parti_volume1 node. Initially the two most important settings are the Scatter and Extinction settings.

  15. Scatter controls the color and intensity of the effect. This usually does not have to be set very high. Click on the Scatter color swatch, and set the value to 0.15.

    Connect the parti_volume1 node to the Volume Shader slot of the transmat1SG node.

    Figure 9.50. Connect the parti_volume1 node to the Volume Shader slot of the transmat1SG node.

    Extinction controls the falloff for the effect. If this is set to a high value, it can actually affect how far the light travels in the scene from the physical light, creating the look of very dense fog (see Figure 9.51).

    The Scatter and Extinction settings are the most important controls for the parti_volume1 node. They should be set to low values.

    Figure 9.51. The Scatter and Extinction settings are the most important controls for the parti_volume1 node. They should be set to low values.

  16. Set the Extinction value to 0.02.

    The Scatter, Extinction, and Physical Light values work together to create the effect. When using PM in your own scenes, you'll find that you'll have to spend some time experimenting with these settings to get the exact look you want.

  17. The Min Step Len and Max Step Len attributes contribute to the sampling quality of the effect. Lowering these values produces higher-quality renders and longer render times. Set the minimum to 1 and the maximum to 5.

    The result is grainy, but it gives you a general idea of how the PM will look. When you're ready for a high-quality render, set the minimum to a value of 0.1 and the maximum to 5.

  18. Open the Render Settings window, and switch to the Features tab. Under Extra Features, enable Auto Volume. If this is not enabled, the PM effect will not appear in the render. This is a change from previous versions of Maya.

  19. Select the Globe group in the Outliner, open the Hypershade, and apply the globeShader to the Globe group. Create a test render of the scene from the renderCam camera. You do not need to turn on Final Gathering or Global Illumination when using Participating Media.

    Participating Media adds a fair amount of time to the render. The white color outside the window is created by setting the Environment of the renderCam camera to white. The red color of the transparent shader applied to the globe is seen in the light rays that travel through the globe (Figure 9.52).

  20. Save the scene as temple_v10.ma. To see a finished version of the scene, open temple_v10.ma from the chapter9scenes directory on the DVD.

Participating Media adds a lot of drama to the scene.

Figure 9.52. Participating Media adds a lot of drama to the scene.

Tuning Participating Media

Once you have the Participating Media rig working, you can adjust the settings on the parti_volume1 node to tune the effect.

R, G1, and G2 sliders

These sliders control the intensity of the scattered light based on the scatter direction (forward or backward scattering). These sliders are based on the physical properties of how light scatters in a particulate medium and the incidence angle at which the light is viewed. The values should typically range between −1 and 1. Combinations of different values can be used to achieve very specific results; however, some research will be required to obtain the values you need. For more detailed information on how these work refer to Mental Ray for Maya, 3dsMax, and XSI by Boaz Livny (Sybex, 2008).

Height

This setting controls the height of the effect in the scene. If you would like to create the look of a low, dense fog clinging to the surface of a lake, you would set the height of the fog using this value. The Height value works only when the Mode slider is set to 1. Furthermore, the Mode slider has only two options, 0 and 1. The only reason you would need to change the mode to 1 is to activate the Height value.

Light Dist

This value optimizes sampling from area lights when they are used to illuminate the PM.

Light Linking controls

These controls restrict the PM effect to the light listed in the field. If this is left blank, the PM effect will use all the lights in the volume. You can optimize render times by connecting only the lights you need.

Nonuniform slider

This slider adds turbulent noise to the PM effect.

Rendering Participating Media with Indirect Lighting

PM effects can be very expensive to render, and when indirect lighting is added to the scene, the render times become unreasonable for production. There are two approaches that can optimize render times:

You can disable PM and render the scene with indirect lighting (Final Gathering, Global Illumination), save the maps created for the indirect lighting, and then reuse the maps (set the Rebuild function to Freeze). You can then enable PM and render using the stored maps for Final Gathering and Global Illumination.

The other approach is to render the PM effects as a separate pass and then composite the PM pass together with the indirect lighting pass in your compositing software.

You can use Participating Media with any physical light, including the Light Portal arrangement discussed earlier in the chapter. You may need to increase the Multiplier value on the mia_physicalsky1 node (see Figure 9.53).

The temple scene rendered with the Portal Light shader and Participating Media

Figure 9.53. The temple scene rendered with the Portal Light shader and Participating Media

The Bottom Line

Use shadow-casting lights.

Lights can cast either depth map or ray trace shadows. Depth map shadows are created from an image projected from the shadow-casting light, which reads the depth information of the scene. Ray trace shadows are calculated by tracing rays from the light source to the rendering camera.

Master it

Compare mental ray depth map shadows to ray trace shadows. Render the crystalGlobe.ma scene using soft ray trace shadows.

Render with Global Illumination.

Global Illumination simulates indirect lighting by emitting photons into a scene. Global Illumination photons react with surfaces that have diffuse shaders. Caustics use photons that react to surfaces with reflective shaders. Global Illumination works particularly well in indoor lighting situations.

Master it

Render the rotunda_v01.ma scene using Global Illumination.

Render with Final Gathering.

Final Gathering is another method for creating indirect lighting. Final Gathering points are shot into the scene from the rendering camera. Final Gathering includes color bleeding and ambient occlusion shadowing as part of the indirect lighting. Final Gathering can be used on its own or in combination with Global Illumination.

Master it

Create a fluorescent light bulb from geometry that can light a room.

Use Image-Based Lighting.

Image-Based Lighting (IBL) uses an image to create lighting in a scene. High Dynamic Range Images (HDRI) are usually the most effective source for IBL. There are three ways to render with IBL: Final Gathering, Global Illumination, and with the light shader. These can also be combined if needed.

Master it

Render the car scene using the Uffizi Gallery probe HDR image available at www.debevec.org/Probes/.

Render using physical sun and sky.

The Physical Sun and Sky network creates realistic sunlight that's ideal for outdoor rendering.

Master it

Render a short animation showing the car at different times of day.

Understand mental ray area lights.

mental ray area lights are activated in the mental ray section of an area light's shape node when the Use Light Shape option is enabled. mental ray area lights render realistic, soft ray trace shadows. The light created from mental ray area lights is emitted from a three-dimensional array of lights as opposed to an infinitely small point in space.

Master it

Build a lamp model that realistically lights a scene using an area light.

Work with mental ray light shaders.

mental ray has a number of shaders that can be applied to lights to extend their capabilities in a scene. One of these shaders is the Portal Light shader, which helps focus Final Gathering points around light entering a room through an opening.

Master it

Render the rotunda_v01.ma scene using the Portal Light shader.

Create Participating Media.

Participating Media (PM) refers to particulate matter suspended in the air. Light is reflected from PM, creating the streaming beams of light known as volumetric lighting. Several shaders can be set up to create the look of PM in a mental ray render.

Master it

Render a beam of light coming from a flashlight model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset