Chapter 10. mental ray Shaders

mental ray is a rendering plug-in that is included with Maya. It is a professional-quality photorealistic renderer used throughout the industry in film, television, architectural visualization, and anywhere photorealism is required.

Learning mental ray takes time and practice. Even though it's a plug-in, you'll find that it is as deep and extensive as Maya itself. mental ray includes a library of custom shading nodes that work together to extend the capabilities of mental ray. There are a lot of these nodes, many more than can be covered in this book.

In this chapter you will learn to:

  • Use ambient occlusion

  • Understand shading concepts

  • Apply reflection and refraction blur

  • Use basic mental ray shaders

  • Apply the car paint material

  • Use the MIA materials

  • Control exposure using tone mapping

  • Render contours

Ambient Occlusion

Ambient occlusion refers to a type of shadowing that occurs when the ambient light in an environment is occluded (blocked) from reaching a surface by other nearby objects or other parts of the same object. You can see ambient occlusion effects in the photograph in Figure 10.1. The darkness that occurs in the cracks and crevices in the plaster design on an overcast day is a perfect example of ambient occlusion.

Ambient occlusion effects are seen in many renders created using Final Gathering. However, you may have noticed while working through the exercises in Chapter 9 that the ambient occlusion that occurs in a Final Gathering render lacks a certain amount of detail. Unless you increase the number of Final Gathering rays, detailed ambient occlusion shadows are difficult to achieve, and the more rays you emit into a scene, the longer the render time will be.

Ambient occlusion occurs when photons of light are unable to reach the cracks and crevices of a surface.

Figure 10.1. Ambient occlusion occurs when photons of light are unable to reach the cracks and crevices of a surface.

mental ray has a special ambient occlusion texture node that you can use to create detailed ambient occlusion shadowing while maintaining reasonable render times. The texture is usually used in one of two ways. You can connect it as part of a shader network to include ambient occlusion within a rendered image, or you can use the material to create a separate ambient occlusion pass. This ambient occlusion render pass can then be used in a composite to add the shadowing effects to the color pass.

This latter method is the most common approach and offers the most flexibility: the occlusion pass can easily be modified in the compositing software (such as Adobe After Effects or Autodesk Toxic), eliminating the need to re-render the entire scene if a change needs to be made. In this way you can use the ambient occlusion texture to augment the shadowing of a render pass that uses Final Gathering or as a substitute for rendering with Final Gathering.

Reflection occlusion is similar to ambient occlusion. Reflection occurs when light rays are reflected off a surface. If fewer light rays can reach a reflective surface because of nearby occluding surfaces, then reflection occlusion is the result. Areas of a surface within crevices or near other objects are less reflective than the fully exposed parts of the surface. Reflection occlusion is available as a mode of the ambient occlusion texture.

In this section you'll learn how to use the ambient occlusion node.

Create an Ambient Occlusion Shader

In this exercise you'll apply the ambient occlusion texture to the out color of a surface shader that is applied to all the objects in a scene. You can apply the shader to all the objects in a scene and place the objects on a separate render layer to create your own custom occlusion pass. Using Render layers is discussed in Chapter 12.

  1. Open the carScene_v01.ma scene from the chapter10scenes directory on the DVD. The scene has the three-wheeled vehicle in a futuristic setting created by Anthony Honn.

  2. Create a render from the renderCam (make sure mental ray is chosen as the current renderer).

    Currently there is a basic white Lambert shader applied to the car and a gray Lambert shader applied to the scenery. The default light is enabled in the Render Settings window.

  3. Open the Outliner, and Shift+click all of the group nodes and the glass object. From the Rendering menu set choose Lighting/Shading

    Understanding mental ray Shader Nodes
    Apply a surface shader to the geometry in the scene.

    Figure 10.2. Apply a surface shader to the geometry in the scene.

  4. Open the Hypershade window (Window

    Apply a surface shader to the geometry in the scene.
  5. On the left column of the Hypershade, set the mode of the Create tab to Create mental ray Nodes. Expand the Textures rollout, and click the mib_amb_occlusion button to create an ambient occlusion texture. It should appear in the Work Area of the Hypershade.

  6. In the Work Area of the Hypershade, MMB-drag the mib_amb_occlusion1 node on top of the surfaceShader1 node, and choose Default from the pop-up. This connects the ambient occlusion node to the outColor channel of the surface shader (see Figure 10.3).

    Surface shaders are the simplest of all shaders. They do not react to the lighting in the scene at all. The outColor channel applies a flat color to all the geometry that uses the shader. By connecting the ambient occlusion texture to the out color, you'll see only the effects of the ambient occlusion node on the geometry. Any lighting or other surface properties in the scene will be overridden by the ambient occlusion texture.

    Apply a surface shader to the geometry in the scene.

    Figure 10.3. Apply a surface shader to the geometry in the scene.

  7. In the render view, create a test render of the scene from the renderCam camera (see Figure 10.4).

    The render takes a while (two minutes on my machine), partly because of the car's complex geometry and partly because the occlusion texture needs to be tuned to maximize efficiency. You'll also notice the image is very grainy. To fix these problems, let's look at how ambient occlusion is calculated.

    Render the scene using a surface shader with an ambient occlusion node connected to the outColor channel.

    Figure 10.4. Render the scene using a surface shader with an ambient occlusion node connected to the outColor channel.

    Ambient occlusion uses ray tracing to determine how the shading of a surface is colored. When a ray from the camera intersects with geometry that has the ambient occlusion texture applied, a number of secondary rays are shot from the point of intersection on the surface back into the scene. Imagine all the secondary rays as a hemisphere above each point on the surface that receives an initial ray from the camera. If the secondary ray detects another object (or part of the same object) within a given distance from the original surface, that point on the original surface has a dark color applied. If no other nearby surfaces are detected, then a light color is applied. The level of dark or light color is determined by the proximity of nearby surfaces.

  8. In the Render View window, store the current image so you can compare it with future renders. Select the mib_amb_occlusion node in the Hypershade, and open its Attribute Editor.

  9. The Samples attribute adjusts the overall quality of the ambient occlusion shading. Raising this setting improves quality but also increases render times. Set this to 32.

    The bright and dark colors determine how a surface is shaded based on the proximity of other surfaces or parts of the same surface. If you reverse these colors, you'll see the negative image of the previous render.

    The Max Distance attribute determines how much of the scene is sampled. Think of this as the distance the secondary rays travel in the scene as they search out nearby surfaces. If a nearby object is beyond the Max Distance, then it will not affect how ambient occlusion is calculated because the secondary rays will never reach it. When Max Distance is set to 0, the entire scene is sampled; the Max Distance is essentially infinite.

    One of the best ways to increase efficiency in the scene is to establish a value for Max Distance. This decreases the render time and improves the look of the image. Determining the proper value for Max Distance often takes a little experimentation and a few test renders. You want to find the value that offers the type of shadowing you need within a reasonable render time.

    Spread determines the distance of the shading effect across the surface. Think of this as the size of the shadow. Higher values produce larger areas of shadowing on the surface; lower values produce tighter shadows.

  10. Set Max Distance to 20 and create another test render; compare this with the previous render.

    The render takes about half the time as the original render, and there is less noise in the lighter areas. The overall image is brighter because fewer objects are within the range of Max Distance, and thus there are fewer objects creating shadows on the surface.

    The Falloff attribute modifies Max Distance. Lowering this value will produce darker shadows in crevices and softer shadows at the edges of the Max Distance. In practice, use Spread, Max Distance, and Falloff together to tune the look of the ambient occlusion shading (see Figure 10.5).

    The attributes for the ambient occlusion texture

    Figure 10.5. The attributes for the ambient occlusion texture

    The Id Incexcl and Id Nonself attributes are two ways in which you can segregate occlusion shading by surface. If you have a scene in which there are multiple ambient occlusion textures applied to different objects, setting the Id Incexcl setting to a non-zero value either includes or excludes the surfaces from the effects of ambient occlusion.

    If you set Id Incexcl to a positive value, the object is excluded from ambient occlusion; if you set it to a negative value, the object is included. A value of zero means that the object is always included in the ambient occlusion calculation.

  11. Save the scene as car_scene_v02.ma. To see a version of the scene, open carScene_v02.ma from the chapter10scenes directory on the DVD.

Ambient Occlusion and Bump Textures

One drawback to using a surface shader to create the ambient occlusion effect is that surface shaders do not have a bump channel. You may want to include a bump texture in the ambient occlusion calculation. In this situation it may be desirable to use a Lambert shader instead of a surface shader.

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

  2. In the Outliner, expand the platform group and select the platformSurface object. Apply a Lambert shader to this object (Lighting/Shading

    Ambient Occlusion and Bump Textures
  3. Open the Attribute Editor for the new Lambert material, and click on the checkered box to the right of the Bump Mapping field. From the Create Render Node pop-up, click the Textures tab and choose SolidFractal from the 3D Textures section.

  4. Open the Hypershade, and switch to the Textures tab. With the new Lambert shader open in the Attribute Editor, MMB-drag the mib_amb_occlusion1 node from the Textures section of the Hypershade on top of the Incandescence channel of the Lambert shader.

  5. Set the Color of the Lambert Shader to black so lighting from the scene does not affect the shader. Create a test render of the scene; the bump texture appears on the platform as part of the ambient occlusion shading (see Figure 10.6). This will also work for displacement maps and normal maps.

    Render the scene using a surface shader with an ambient occlusion node connected to the outColor channel.

    Figure 10.6. Render the scene using a surface shader with an ambient occlusion node connected to the outColor channel.

    By using the same ambient occlusion texture for the surface shader and the Lambert shader, you only have to worry about changing the setting on one ambient occlusion node.

  6. Save the scene as carScene_v03.ma. To see a version of the scene to this point, open the carScene_v03.ma file from the chapter10scenes directory on the DVD.

Reflection Occlusion

By default the ambient occlusion node creates ambient occlusion shading for diffuse surfaces. You can use the same texture node to create occlusion for reflective surfaces. As stated before, if fewer light rays reach a reflective surface because of occluding surfaces (surfaces that block the light rays), the surface appears less reflective. The cracks and crevices on the vehicle's wheels provide a good example of this situation.

  1. Open the carScene_v04.ma file from the chapter10scenes directory on the DVD.

    In this version of the scene, a Physical Sun and Sky network has been added to the scene, and Final Gathering is enabled. A Blinn texture named wheelShader has been applied to the wheels of the car. The Reflectivity of the Blinn is at 1 (or 100 percent), so the wheels will resemble chrome when rendered.

  2. Create a render from the renderCam camera in the Render View window.

    The wheels are 100 percent reflective, which makes them appear somewhat unrealistic (see Figure 10.7). You can tone down the reflectivity in the crevices of the wheel geometry, which will help make them appear more realistic and the details more visible.

    The wheels are 100 percent reflective, making them appear less realistic. Much of the detail of the wheels is lost in the reflection.

    Figure 10.7. The wheels are 100 percent reflective, making them appear less realistic. Much of the detail of the wheels is lost in the reflection.

  3. Open the Hypershade window, and MMB-drag the wheelShader from the Materials library down to the Work Area.

  4. Set the Create column on the left side of the Hypershade window to Create mental ray Nodes. Expand the Textures section, and click the mib_amb_occlusion button to create an ambient occlusion node.

    When you connect the ambient occlusion texture to a shader, you want to use the outColor attribute of the texture as the output. The outColor attribute is a vector, meaning it has three components (the red channel, the blue channel, and the green channel). To modify the Blinn texture, connect the color output of the ambient occlusion texture into the Reflectivity attribute of the wheelShader. However, the Reflectivity channel accepts only an input that has a single component, not a vector. To make the two channels compatible, you can use the Luminance color utility. This converts the vector output of the ambient occlusion texture into a single value, which can then be connected to the Reflectivity channel of the wheelShader.

  5. In the Create column on the left of the Hypershade, set the mode to Create Maya Nodes.

  6. Scroll down to the Color Utilities section, expand it, and click the Luminance button to create the Luminance utility.

  7. In the Work Area of the Hypershade, MMB-drag the mib_amb_occlusion1 node on top of the luminance node. Choose Value from the pop-up window.

  8. MMB-drag the luminance node on top of the wheel shader. Choose Other from the pop-up window. This opens the Connection Editor.

  9. In the Connection Editor, select outValue on the left and the Reflectivity channel on the right (you may need to scroll to the bottom of the list; see Figure 10.8).

  10. Open the Attribute Editor for the mib_amb_occlusion1 node. Set Samples to 32 and Max Distance to 20, and activate the Reflective option.

  11. Create a test render from the renderCam camera, and compare it to the original render created at the start of the section (see Figure 10.9).

    Connect the ambient occlusion texture to the Reflectivity channel of the wheelShader using a Luminance color utility node.

    Figure 10.8. Connect the ambient occlusion texture to the Reflectivity channel of the wheelShader using a Luminance color utility node.

    The reflection occlusion helps bring out the detail of the wheels and makes much more realistic-looking chrome.

    Figure 10.9. The reflection occlusion helps bring out the detail of the wheels and makes much more realistic-looking chrome.

    The ambient occlusion texture makes the wheels look more realistic by controlling the amount of reflectivity in the cracks and crevices of the surface to bring out the detail. The wheels are now a bit closer to looking realistic.

    You can use a reflection occlusion texture to create a separate render pass the same way that you created an ambient occlusion pass at the start of the chapter. All you need to do is use an ambient occlusion texture with the Reflective option activated for reflective surfaces and a standard ambient occlusion texture for diffuse surfaces. Render them all out in a single pass, or split them into separate passes and use the images to modify the render in your compositing software.

  12. Save the scene as carScene_v05.ma. To see a version of the scene to this point, open the carScene_v05.ma file from the chapter10scenes folder on the DVD.

Additional Ambient Occlusion Techniques

There are several additional ambient occlusion nodes and techniques that you can use to increase efficiency or for special circumstances.

Fast Occlusion

The mib_fast_occlusion texture can be used to increase the speed of an occlusion pass. This shader utilizes the ambient occlusion shading that is built into the mental ray renderer. This is a new feature of mental ray for Maya, which is part of the redesigned render pass workflow discussed in Chapter 12.

For the most part, the setup and attributes are very similar to those of the standard ambient occlusion shader. However, there are several options that need to be enabled in the Render Settings window; otherwise you won't see any results when you use the shader. In the Features tab of the Render Settings window, make sure the Ambient Occlusion option is enabled. If this is not enabled, you'll see a flat white color or no effect from the occlusion texture.

In the Indirect Lighting section of the Render Settings window, enable Ambient Occlusion; then use the Cache settings to determine the number of rays and cache points used to calculate ambient occlusion. A higher number of points creates a smoother render but also results in less detail. The Cache Points attribute on the mib_fast_occlusion texture overrides the Cache Points setting in the Indirect Illumination tab of the Render Settings window.

The difference in quality between the mib_fast_occlusion shader and the standard mib_occlusion shader should be negligible in most situations. However, your own results may vary. You should experiment with both shaders and compare the results in terms of both quality and render time.

Ambient Occlusion and Transparency

If you're using a shader that has a texture in the Transparency channel, you'll find that the standard ambient occlusion textures will not calculate the transparency correctly. To fix this you can create a custom shader network and render with Final Gathering. This exercise demonstrates the technique.

  1. Open the occlusionTransparency_v01.ma scene from the chapter10scenes directory on the DVD. This scene has two planes, one on top of the other.

  2. Open the Render Settings window, and make sure the Renderer is set to mental ray. In the Quality tab, set the Quality Presets option to Production. In the Indirect Lighting tab, turn on Final Gathering and set Accuracy to 400.

  3. Create a Lambert shader and apply it to the upperPlane object. Name the shader transparentOcclusion.

  4. Open the Hypershade window, and MMB-drag the transparentOcclusion shader from the Materials tab into the Work Area of the Hypershade.

  5. Create a grid texture (under 2D textures in the Create Maya Nodes mode of the left-hand column).

  6. Set the Create tab in the left-hand column to Create mental ray Nodes. Expand the MentalRay Lights section, and choose mib_fg_occlusion to create an mib_fg_occlusion node.

  7. Expand the Sample Compositing section lower in the left column, and create an mib_transparency node (see Figure 10.10).

    The mib_transparency node allows for the correct calculation of the Final Gathering rays as they pass through the transparent parts of the texture. The mib_fg_occlusion shader is a simple switch. If Final Gathering (FG) is on in the Render Settings window, the shader renders ambient occlusion shadowing effects much like the ambient occlusion texture. If Final Gathering is off, it returns the Color When Off value set in its Attribute Editor.

    Create the grid texture, mib_fg_occlusion, mib_transparency, and transparentOcclusion shader nodes, and place them in the Work Area of the Hypershade.

    Figure 10.10. Create the grid texture, mib_fg_occlusion, mib_transparency, and transparentOcclusion shader nodes, and place them in the Work Area of the Hypershade.

    You can connect an ambient occlusion texture to the Color When Off value so that the shader acts as a switch. When FG is on, you get ambient occlusion shading as calculated by Final Gathering points. When FG is off, you get standard ambient occlusion shading, courtesy of the mib_amb_occlusion texture connected to the Color When Off attribute.

    The mib_transparency node will allow for the correct calculation of the Final Gathering rays as they pass through the transparent parts of a texture.

  8. In the Work Area of the Hypershade, connect the outColor channel of the grid texture to the Transparency channel of the mib_transparency1 node.

  9. Open the grid texture's Attribute Editor, and set U Width and V Width to 0.5. This makes the squares of the grid smaller so it's easier to see the effect of the occlusion shading.

  10. Connect the mib_fg_occlusion node's outValue to the mib_transparency1 node's Input channel.

  11. Select the transparencyOcclusion shader, and graph its input and output connections. Select the shading group node, and open its Attribute Editor. Expand the mental ray section, and find the Custom Shaders section.

    The shading group node is the node labeled lambert2SG. It is the node that serves as an interface between the shader, the geometry, and the lights in the scene. It's also where you'll find many of the connections for mental ray override shaders. Every Maya shader that has been applied to geometry in a scene has an associated shading group node. When working with mental ray nodes, you'll be using the shading group node a lot.

  12. Drag the mib_transparency1 shader from the Utilities tab of the Hypershade to the Material Shader slot in the lambert2SG node (see Figure 10.11).

    This completes the shader for the upper plane. However, you'll need a custom shader for the lower plane so the ambient occlusion shadowing effect is calculated correctly for both surfaces.

  13. Create a surface shader, and apply it to the lowerPlane object.

  14. Connect the mib_fg_occlusion1 node (the same one that's connected to the network applied to the upper plane) to the outColor channel of the surface shader.

  15. Create a test render to see the result; it should look like Figure 10.12.

  16. To see a version of the scene with the network set up, open the occlusionTransparency_v02.ma scene from the chapter10scenes directory on the DVD.

Connect the mib_transparency1 node to the lambert2SG node's Material Shader attribute.

Figure 10.11. Connect the mib_transparency1 node to the lambert2SG node's Material Shader attribute.

The transparency on the upper plane is calculated correctly showing the proper ambient occlusion shading for the two panes.

Figure 10.12. The transparency on the upper plane is calculated correctly showing the proper ambient occlusion shading for the two panes.

Shading Concepts

Shaders are sets of specified properties that define how a surface reacts to lighting in a scene. A mental ray material is a text file that contains a description of those properties. In Maya, the Hypershade provides you with a graphical user interface so you can edit and connect shaders without writing or editing the text files themselves. The terms shader and material are synonymous; you'll see them used interchangeably through the book and the Maya interface. mental ray also uses shaders to determine properties for lights, cameras, and other types of render nodes.

Three key concepts that determine how a shader makes a surface react to light are diffusion, reflection, and refraction. Generally speaking, light rays are reflected or absorbed or pass through a surface. Diffusion and reflection are two ways in which light rays bounce off a surface and back into the environment. Refraction refers to how a light ray is bent as it passes through a transparent surface.

Diffusion

Diffusion describes how a light ray is reflected off of a rough surface. Think of light rays striking concrete. Concrete is a rough surface covered in tiny bumps and crevices. As a light ray hits the bumpy surface, it is reflected back into the environment at different angles, which diffuse the reflection of light across the surface (see Figure 10.13).

You see the surface color of the concrete mixed with the color of the lighting, but you generally don't see the reflected image of nearby objects. A sheet of paper, a painted wall, and clothing are examples of diffuse surfaces.

In standard Maya shaders, diffusion is controlled using the Diffuse slider. A Lambert shader, named for the eighteenth-century Swiss physicist Johann Heinrich Lambert, is commonly used for diffuse surfaces that have no specular reflectivity.

Light rays that hit a rough surface are reflected back into the environment at different angles, diffusing light across the surface.

Figure 10.13. Light rays that hit a rough surface are reflected back into the environment at different angles, diffusing light across the surface.

Reflection

When a surface is smooth, light rays bounce off the surface and back into the environment. The angle at which they bounce off the surface is equivalent to the angle in which they strike the surface—this is the incidence angle. This type of reflection is known as a specular reflection. You can see the reflected image of surrounding objects on the surface of smooth, reflective objects. Mirrors, polished wood, and opaque liquids are examples of reflective surfaces. A specular highlight is a reflection of the light source on the surface of the object (see Figure 10.14).

Logically smoother surfaces, or surfaces that have a specular reflectivity, are less diffuse. However, many surfaces are composed of layers (think of glossy paper) that have both diffuse and specular reflectivity.

A glossy reflection occurs when the surface is not perfectly smooth, but not so rough as to completely diffuse the light rays. The reflected image on a surface is blurry and bumpy and otherwise imperfect. Glossy surfaces can represent those surfaces that fit between diffuse reflectivity and specular reflectivity.

Light rays that hit a smooth surface and are reflected back into the environment at an angle equivalent to the incidence of the light angle

Figure 10.14. Light rays that hit a smooth surface and are reflected back into the environment at an angle equivalent to the incidence of the light angle

Refraction

A transparent surface can change the direction of the light rays as they pass through the surface (Figure 10.15). The bending of light rays can distort the image of objects on the other side of the surface. Think of an object placed behind a glass of water. The image of the object as you look through the glass of water is distorted relative to an unobstructed view of the object. Both the glass and the water in the glass bend the light rays as they pass through.

The refraction index is a value that describes the amount in which the speed of the light rays is reduced as it travels through a transparent medium, as compared to the speed of light as it travels through a vacuum. The reduction in speed is related to the angle in which the light rays are bent as they move through the material. A refraction index of 1 means the light rays are not bent. Glass typically has a refraction index between 1.5 and 1.6; water has a refraction index of 1.33.

Refraction changes the direction of light rays as they pass through a transparent surface.

Figure 10.15. Refraction changes the direction of light rays as they pass through a transparent surface.

If the refracting surface has imperfections, this can further scatter the light rays as they pass through the surface. This creates a glossy/blurry refraction.

Refraction in Maya is available only when ray tracing is enabled (mental ray uses ray tracing by default). The controls for refraction are found in the Raytrace section of the Attribute Editor of standard Maya shaders. A shader must have some amount of transparency before refraction has any visible effect.

The Fresnel Effect

The Fresnel effect is named for the nineteenth-century French physicist Jean Agustin Fresnel (pronounced with a silent s). This effect describes the amount of reflection and refraction that occurs on a surface as the viewing angle changes. The glancing angle is the angle at which you view a surface. If you are standing in front of a wall, the glancing angle is 0 and the wall is perpendicular. If you are looking across the ocean, the glancing angle of the surface of the water is very high. The Fresnel effect states that as the glancing angle increases, the surface becomes more reflective than refractive. It's easy to see objects in water as you stare straight down into water (low glancing angle); however, as you stare across the surface of water, the reflectivity increases, and the reflection of the sky and the environment makes it increasingly difficult to see objects in the water.

Opaque, reflective objects also demonstrate this effect. As you look at a billiard ball, the environment is more easily seen reflected on the edges of the ball as they turn away from you than on the parts of the ball that are perpendicular to your view (see Figure 10.16).

A demonstration of the Fresnel effect on reflective surfaces: the reflectivity increases on the parts of the sphere that turn away from the camera.

Figure 10.16. A demonstration of the Fresnel effect on reflective surfaces: the reflectivity increases on the parts of the sphere that turn away from the camera.

Using Reflections and Refraction Blur

Standard Maya shaders, such as the Blinn and Phong shaders, take advantage of mental ray reflection and refraction blurring to simulate realistic material behaviors. These options are available in the mental ray section of the shader's Attribute Editor. Blurry reflective and refractive surfaces are also referred to as glossy surfaces.

Reflection Blur

Reflection blur is easy to use and is available for any of the reflective shaders, such as Blinn, Phong, Anisotropic, and Ramp. This exercise demonstrates how to add reflection blur to a Blinn shader.

  1. Open the crystalGlobe_v01.ma file from the chapter10scenes directory on the DVD.

    The scene shows the crystal globe and stand. The scene uses the Physical Sun and Sky network to create simple lighting.

  2. Select the ground plane and apply a Blinn material. Set the Reflectivity of the Blinn material to 1 and the Diffuse value to 0. Then render the scene in the render view from the renderCam camera.

  3. Open the Attribute Editor for the Blinn shader that is applied to the ground. Expand the mental ray section and increase Mi Reflection Blur to 3. Create another test render, and compare this to the render in the previous step (Figure 10.17).

    Add a blurred reflection to the ground plane (right image).

    Figure 10.17. Add a blurred reflection to the ground plane (right image).

Reflection Blur Limit sets the number of times the reflection blur itself is seen in other reflective surfaces. Increasing the Reflection Rays value increases the quality of the blurring, making it appear finer. Notice that the reflection becomes increasingly blurry as the distance between the reflective surface and the reflected object increases.

Many surfaces are more reflective than you may realize. A wooden tabletop or even concrete can have a small amount of reflection. Adding a low reflectivity value plus reflection blurring to many surfaces increases the realism of the scene.

Refraction Blur

Refraction blur is similar to reflection blur. It blurs the objects that appear in a refracted surface. This gives a translucent quality to the object.

  1. Continue with the scene from the previous section. In the Outliner, expand the globe group and select the crystal object. Assign a Blinn shader to the object.

  2. Set Reflectivity of the new Blinn texture to 0 so you can clearly see the refractions.

  3. Set Transparency of the object to light gray.

  4. Expand Raytrace Options, and activate the Refractions option. Set Refractive Index to 1.4.

  5. Render the scene from the renderCam camera, and store the image in the Render View window.

  6. Expand the mental ray section in the Blinn's Attribute Editor. Set Mi Refraction Blur to 5, and create another test render (Figure 10.18).

  7. Save the scene as crystalGlobe_v02.ma. To see a version of the scene, open the crystalGlobe_v02.ma file from the chapter10scenes directory on the DVD.

Refraction Blur Limit sets the number of times the refraction blur itself will be seen in refractive surfaces. Increasing the value of Refraction Rays increases the quality of the blurring, making it appear finer.

Add a blurred refraction to the surface of the crystal globe (right image).

Figure 10.18. Add a blurred refraction to the surface of the crystal globe (right image).

Basic mental ray Shaders

mental ray has a number of shaders designed to maximize your options when creating reflections, glossy reflections, and refractions. Choosing a shader should be based on a balance between the quality of the material you want to create and the amount of time and processing power you wish to devote to rendering the scene. This section looks at a few of the shaders available for creating various types of reflections and refractions. These shaders are by no means the only way to create reflections and refractions. As discussed in previous sections, standard Maya shaders also have a number of mental ray–specific options for controlling reflection and refraction.

DGS Shaders

Diffuse Glossy Specular (DGS) shaders have very simple controls for creating different reflective qualities for a surface as well as additional controls for transparency and refraction. The reflections and refractions created by this shader are physically accurate. In this exercise you'll apply the material to the helmet model created in Chapter 3.

  1. Open the helmet_v01.ma scene from the chapter10scenes directory on the DVD.

  2. Open the render view, and create a render using the renderCam camera. Store the render in the Render View window.

    The scene has a very simple light setup. The key lighting is provided by a mental ray area light, which can be seen as a specular highlight on the orange metal of the helmet and on the glass face shield. The fill lighting is supplied by two directional lights; these lights have their specularity turned off so they are not seen as reflections on the surface of the helmet (see Figure 10.19).

    The helmet uses standard Maya shaders. The metal of the helmet uses an orange Blinn, the face shield uses a transparent Blinn, and the helmet details and the woman's head use Lambert shaders. The grainy quality of the shadows results from the low sampling level set for the area light. By keeping the samples low, the image renders in a fairly short amount of time (under a minute on my machine). The reflection of the checkerboard plane beneath the helmet is clearly seen in the metal of the helmet and on the face shield.

  3. Open the Hypershade window. In the Create tab on the left column, switch the mode to Create mental ray Nodes. Under Materials, click the dgs_material twice to create two DGS material nodes. Name the first one helmet_dgs and the second shield_dgs.

    The space helmet rendered with simple lighting and standard Maya shaders

    Figure 10.19. The space helmet rendered with simple lighting and standard Maya shaders

  4. In the Outliner, select the group labeled helmetSurfaces. In the Hypershade, right-click the helmet_dgs shader and choose Assign dgs_material1SG from the marking menu. This assigns the material to all the objects in the group.

  5. In the Outliner, select the shield surface. In the Hypershade, right-click the shield_dgs material, and choose Assign dgs_material2SG from the marking menu.

  6. In the Hypershade, select the helmet_dgs material and open its Attribute Editor. Set the Diffuse color to bright orange. Set Glossy to black and Specular to white.

  7. In the Hypershade, select the shield_dgs material. Set Transparency to 0.8. Set Glossy to black and Specular to white.

  8. In the render view, render the scene from the renderCam camera. Compare this render to the previous render. Immediately you'll notice a lot of strange things going on with the materials you just applied (see Figure 10.20).

    If you compare Figure 10.20 with Figure 10.19, you should notice a few details:

    • The surfaces are reflective; however, there is no specular highlight (reflection of the light source) on either the helmet surfaces or the glass shield.

    • The shadow of the face shield that falls on the checkered floor is not transparent in Figure 10.20, but it is transparent in Figure 10.19.

      The helmet and face shield surfaces have DGS shaders applied.

      Figure 10.20. The helmet and face shield surfaces have DGS shaders applied.

      Let's look at how to solve these problems. The shader is meant to be physically accurate. The Specular attribute refers to the reflectivity of the shader. In standard Maya shaders, reflectivity and specularity are separated (however, increasing one affects the intensity of the other). In the DGS shader, the Specular channel controls the reflection of visible objects, so a light source must be visible to be seen in the specular reflections.

  9. Select the area light in the Hypershade and open its Attribute Editor. In the areaLightShape1 tab, expand the mental ray attributes and activate the Visible option.

  10. Render the scene again. This time you can see a reflection of the light in the surfaces. You can clearly see that the light is square shaped.

    Glossy reflections, on the other hand, automatically render the reflection of a light source regardless of whether the light source is set to visible or not. The Glossy attribute on the DGS shader controls how reflections are scattered across the surface of an object. The term specular highlight with regard to shading models implies a certain amount of glossiness. Understandably, it's confusing when talking about specular reflections and specular highlights as two different things. The bottom line is this: To make a specular highlight appear in a DGS shader, either the light has to be visible when the Specular attribute is above zero and Glossy is set to zero or the Glossy setting must be above zero.

    Glossy reflections can be blurry or sharp. To control the blurriness of a glossy reflection, you need to adjust the Shiny setting. Lower Shiny values create blurry reflections; higher Shiny values create sharp reflections.

  11. Select the helmet_dgs shader and open its Attribute Editor. Set Glossy to a medium gray; set the Specular color to black. Set Shiny to 10 and create another render. This time the surface of the helmet appears more like painted metal and less like a mirror (upper-left image in Figure 10.21).

    The Shiny U and Shiny V settings control the blurriness of the glossy reflection when Shiny is set to 0. Using these settings you can create an anisotropic type of reflection. Anisotropic reflections appear on surfaces that have a directionality to their roughness. When you look at the surface of a compact disc, the tiny grooves that are created when data is written to the disk create the satinlike anisotropic reflections. Brushed metal, hair, and satin are all examples of materials that have anisotropic specular reflections.

    The U and V values control the direction of the anisotropic reflections across the surface. For best results set one value higher than the other.

  12. Set Shiny to 0. Set the Shiny U value to 3 and the Shiny V value to 10, and create another render; the helmet now appears more like brushed metal (upper-right image in Figure 10.21).

    The Shiny U and Shiny V settings simulate the anisotropic reflections on the material by stretching the reflection along the U or V direction. In this case this is not physically accurate and does not simulate how tiny grooves in the surface affect the reflection.

    When rendering transparent surfaces using the DGS shader, the Specular, Glossy, Transparency, and Refraction settings all work together to create the effect. For transparency to work, the shader must have a Transparency setting higher than zero and either a Specular or a Glossy setting above zero. If Transparency is set to 1 and both Specular and Glossy are set to black, the surface will render as opaque, the same as if Transparency were set to 0.

    The Specular color can be used to color the transparent surface, and the Glossy setting can be used (along with the Shiny settings) to create the look of a translucent material, such as plastic, ice, or frosted glass.

  13. Select the shield_dgs material. Set the Specular color to a light green, and set Transparency to 0.8.

  14. Set Index Of Refraction to 1.1. This makes the glass appear thicker as the light rays are bent as they pass through the glass.

  15. Create another test render. Notice that the green specular color tints both the objects behind the glass as well as the reflections on the surface (lower-left image in Figure 10.21).

  16. To create the look of frosted glass, set Diffuse to light gray, Specular to black, Glossy to light gray, Shiny to 20, Transparency to 0.8, and Index Of Refraction to 1.2.

  17. Create another test render to see the result (lower-right image in Figure 10.21).

    Rendering using different settings for the DGS materials applied to the helmet metal and face shield.

    Figure 10.21. Rendering using different settings for the DGS materials applied to the helmet metal and face shield.

    A few details are worth noting about using the Glossy settings:

    • Specular reflections of all the lights in the scene are visible on the surface when Glossy is above zero. Notice that the highlights of the two directional lights are visible in the glass even though the Specularity option for both lights is disabled. To avoid this, consider using Global Illumination or Final Gathering to create fill lighting in the scene.

    • Glossy reflections and refractions are physically accurate in that objects close to the refractive or reflective surface will appear less blurry than objects that are farther away.

    • To make an object look more metallic, tint the Glossy color similar to the Diffuse color.

    • Try using textures in the Glossy and Specular channels to create more interesting materials.

    • When using the shader on scenes that employ Global Illumination, you need to create a dgs_material_photon node (found in the Photonic Materials section of the mental ray render nodes of the Hypershade). Attach this shader to the shading group of the original DGS material in the Photon Shader slot, and then use the settings on the dgs_material_photon to control the shader.

    • You can increase realism further by rendering a separate reflection occlusion pass to use in a composite or plug occlusion textures into the specular and glossy attributes (enable Reflection on the occlusion textures).

  18. Save the scene as helmet_v02.ma. To see a finished version of the scene, open the helmet_v02.ma scene from the chapter10scenes directory on the DVD.

Dielectric Material

The purpose of the Dielectric material is to accurately simulate the refraction of light as it passes through transparent materials. Use the Dielectric material for glass, water, and other fluids. The term Dielectric refers to a surface that transmits light through multiple layers, redirecting the light waves as they pass through each layer.

If you observe a fish in a glass bowl, the light rays that illuminate the fish in the bowl transition from air to glass, then from glass to water, then again from water back to glass, and finally from glass out into the air on the other side. Each time a light ray makes a transition from one surface to another, the direction of the light ray changes. The index of refraction describes the change in the light ray's direction.

Most standard materials in Maya use a single index of refraction value to simulate the change of direction of the light ray as it is transmitted through the surface. This is not accurate, but it's usually good enough to create a believable effect. However, if you need to create a more physically accurate refractive surface, the Dielectric material is your best choice.

The material is most appropriately used to simulate glass and transparent liquids. This is because it has two settings for the index of refraction that describes the change of the light's ray's direction as it makes a transition from one refractive surface to the next.

In this exercise you'll create a physically accurate rendering of a glass of blue liquid using the Dielectric material. In this example, light will move from the air into glass and then from the glass into the water. The glass is open at the top, so you'll also need to simulate the transition from air to water. This means you'll need to use three dielectric materials: one for air to glass, one for glass to water, and one for air to water. This tutorial is based on Boaz Livny's discussion of the Dielectric material in Mental Ray for Maya, 3ds Max, and XSI by Boaz Livny (Sybex, 2008).

  1. Open glass_v01.ma from the chapter10scenes directory on the DVD.

    In this scene a simple glass has been modeled and split into four surfaces. Each surface represents one of the three transitions that will be simulated using the Dielectric material. To make this easier to visualize, each surface each has a colored Lambert shader applied. The scene is lit using a single spotlight that casts ray trace shadows.

    The four surfaces are named air_glass1, air_glass2, liquid_glass1, and liquid_air1.

  2. Open the Hypershade window. Set the Create tab on the left to Create mental ray Nodes.

  3. Expand the Materials section, and click the dielectric_material button. Name the new dielectric_material1 node air2GlassShader.

  4. Create two more materials and name one glass2LiquidShader and the other liquid2AirShader.

  5. Apply the air2GlassShader to both the airGlass1 and airGlass2 objects. Apply glass2LiquidShader to the liquid_glass1 object and liquid2AirShader to liquid_air1.

  6. Select the air2glassShader and open its Attribute Editor.

    The Index Of Refraction (IOR) for glass is typically 1.5, and the IOR for air is 1. Look at the settings for the air2Glass shader. The Index Of Refraction setting defines the IOR for the material; the Outside Index Of Refraction setting defines the IOR for the medium outside the material. The default settings for the Dielectric material are already set to the proper glass-to-air transition. Index Of Refraction should be set to 1.5, and Outside Index of Refraction should be set to 1.

  7. Set Phong Coefficient to 100 and turn on Ignore Normals.

    The Phong Coefficient creates a specular reflection on the glass. The Dielectric material uses the surface normals of the object to create the refraction effect. If you activate the Ignore Normals option, the shader bases the normal direction on the camera view. For a basic glass model such as this one, you can safely use the Ignore Normals feature.

  8. Select the glass2LiquidShader and open its Attribute Editor. Set Index Of Refraction to 1.33 (the IOR of water is 1.33) and Outside Index Of Refraction to 1.5. Set Phong Coefficient to 100, and turn on Ignore Normals.

  9. Click on the color swatch next to the Col attribute. This determines the color of the shader (why spell out Index Of Refraction in the interface but at the same time abbreviate Color? One of the many mysteries of Maya). In the Color Chooser set Hue (H) to 180, Sat (S) to 0.45, and Value (V) to 1.

  10. Select the liquid2AirShader. Set Index Of Refraction to 1.33 and leave Outside Index Of Refraction at 1. Set Phong Coefficient to 100, and turn on Ignore Normals.

  11. Select the Col swatch, and use the same HSV values in the Color Chooser that you set in step 9.

  12. Open the Render View window, and create a test render from the renderCam camera (see Figure 10.22).

    Render the glass using the Dielectric material (left image). Add transparent shadows by rendering with caustics (right image).

    Figure 10.22. Render the glass using the Dielectric material (left image). Add transparent shadows by rendering with caustics (right image).

You can see that there are differences between the refractions of the various surfaces. Just like the DGS shader, the Dielectric material fails to cast transparent shadows (Figure 10.22, left image). The best solution for this problem is to enable Caustics. When using caustics with the Dielectric shader, you need to connect a dielectric_material_photon material to the Photon Shader slot of the Shading Group node and enable Caustics. The settings for the dielectric_material_photon material should be the same as the settings for the Dielectric material. To see an example of this setup, open the dielectricCaustics.ma scene in the chapter10scenes directory of the DVD. The image on the right of Figure 10.22 shows the glass rendered with Caustics enabled.

mental ray Base Shaders

A number of shaders available in the Hypershade are listed with the prefix mib (mental images base): mib_illum_cooktor, mib_illum_blinn, and so on. These are the mental ray base shaders. You can think of these nodes as building blocks; you can combine them to create custom shaders to create any number of looks for a surface. There are far too many to describe in this chapter, so it's more important that you understand how to work with them. Descriptions of each node are available in the mental ray user guide that is part of the Maya documentation.

In this exercise you'll see how a few of these shaders can be combined to create a custom material for the helmet.

  1. Open the helmet_v03.ma scene from the chapter10scenes folder on the DVD. This scene currently uses standard Maya shaders applied to the geometry.

  2. Open the Hypershade window, and set the mode of the Create tab to Create mental ray Nodes.

  3. Expand the Materials section; you'll see a number of mib materials toward the bottom (see Figure 10.23).

  4. Click the mib_illum_cooktorr button to create a Cook-Torrance material, and open its Attribute Editor.

    Some of the mental ray base shaders are available in the Materials section of the Create mental ray Nodes menu.

    Figure 10.23. Some of the mental ray base shaders are available in the Materials section of the Create mental ray Nodes menu.

    The Cook-Torrance shader creates physically accurate isotropic specular highlighting, meaning that the specular highlights on surfaces are scattered as if the surface was covered with tiny microfacets arranged randomly.

    The look of the highlight is created by setting the Specular color to a value above zero. The Roughness slider determines the spread of the highlight. The shader has three separate controls to determine the Index Of Refraction for each color channel (red, green, and blue). When light is reflected from the tiny bumps on an isotropic surface, the directionality of each light wave changes. The three IOR sliders allow you to specify this directional change for each color channel. This gives the specular highlight the appearance of "color fringing"—a slight tint on the edge of the highlight (this appears as blue fringe in the shader's preview). The color fringing around the highlight make this shader very useful for creating realistic-looking metals.

    The Ward (mib_illum_ward) material is similar to the Cook-Torrance but offers more options for creating realistic anisotropic specularity. The Ward material works best on NURBS surfaces; the mib_illum_ward_deriv shader is a little easier to use, giving you two simple sliders to control the direction of the anisotropy along the U and V coordinates of the surface.

  5. In the Outliner, select the helmetSurfaces group. In the Hypershade, right-click on the mib_illum_cooktorr1 shader, and choose Assign Material To Selection from the marking menu.

  6. In the Attribute Editor, set the Diffuse color to light orange. Set the Specular channel to light gray.

  7. Set Roughness to 0.19.

  8. To create an orange fringe around the highlight, set Index Of Refraction, Red to 80, Index Of Refraction, Green to 10, and Index Of Refraction, Blue to 8.

  9. In the Render View window, create a test render using the renderCam camera (Figure 10.24).

    The Cook-Torrance shader creates fairly realistic metallic highlights.

    Figure 10.24. The Cook-Torrance shader creates fairly realistic metallic highlights.

    The helmet has a very convincing metallic look, but you'll notice there are no reflections. To add reflections you can combine the Cook-Torrance shader with a glossy reflection node.

  10. In the Create tab of the Hypershade, click the mib_glossy_reflection button. Assign the new mib_glossy_reflection1 node to the helmet surfaces group. This overwrites the Cook-Torrance shader that has been applied.

  11. Open the Attribute Editor for the mib_glossy_reflection1 node. From the Hypershade window, MMB-drag the mib_cook_torr1 node from the Hypershade to the Base Material slot of the mib_glossy_reflection1 node (see Figure 10.25).

    Connect the Cook-Torrance shader to the Base Material slot of the mib_glossy_reflection1 node.

    Figure 10.25. Connect the Cook-Torrance shader to the Base Material slot of the mib_glossy_reflection1 node.

  12. Set Reflection Color to white (white sets the shader to maximum reflectivity; darker shades create a less-reflective material), and create another render.

  13. The default settings create a glossy reflection in the helmet surfaces. To adjust the quality and glossiness of the reflections, increase the Samples value to 32.

    The U Spread and V Spread sliders control the glossiness of the reflections, much like the Shiny U and Shiny V settings on the DGS shader. Higher values produce glossier reflections. Using a different value for U than V creates anisotropic specular highlights. Ideally you want to match the glossiness of the reflections on the mib_glossy_reflection1 shader with the glossiness of the highlight on the mib_cooktorr shader.

    You can blend between a reflection of the objects in the scene and an environment reflection. To do this, you first need to create an environment reflection node.

  14. Open the Attribute Editor for the mib_glossy_reflection1 node. Click on the checkered box to the right of the Environment field. From the mental ray tab of the Create Render Node window, scroll down to the Environments section. Click the mib_lookup_background button.

    This connects a mib_lookup_background node to the Environment slot of the mib_glossy_reflection1 node. You can use any of the environment nodes to map an image to the reflection of the environment. Mib_lookup_background works with standard rectangular images. The node sizes the background image to fit the resolution of the rendering camera.

  15. The Attribute Editor should open to the mib_lookup_background1 node. Click on the checkered box next to the Texture tab to add a mental ray texture node. This allows you to map an image to the background.

  16. In the Attribute Editor for the mentalRayTexture1 node, click on the folder next to Image Name. Load the desert.jpg image found in the sourceimages directory in the Chapter10 folder on the DVD.

  17. Select the mib_glossy_reflection1 node, and in its Attribute Editor, set Environment Color to medium gray. This sets the strength of the reflectivity of the environment.

    The shader can create a smooth transition from the reflections of objects in the scene and the environment reflections. The Max Distance attribute sets a limit in the scene for tracing reflections. When reflection rays reach this limit, they stop sampling reflections of objects in the scene and start sampling the image mapped to the environment. The Falloff value determines the smoothness of the transition. The Falloff value is a rate of change. A setting of 1 creates a linear falloff; higher values create a sharper transition.

  18. Set Max Distance to 5 and Falloff to 2. Turn off Single Env Sample, and create another test render. You can see the blue sky of the desert image reflected in the metal of the helmet.

    To increase the realism of the reflections, you can add an ambient occlusion node to decrease the intensity of the reflections in the crevices of the model.

  19. Open the Attribute Editor of the mib_glossy_reflection node. Click on the checkered box next to Reflection Color. From the Create Render Node pop-up, switch to the mental ray tab, and click on the Mib_amb_occlusion node in the Textures section.

  20. Open the Attribute Editor for the mib_mab_occlusion node, set Samples to 32, Bright Color to medium gray, and Dark Color to a very dark gray (but not black). Set Max Distance to 5, and turn on Reflective.

  21. Create another test render of the scene. Now the reflections on the model look much more believable (see Figure 10.26).

    The Cook-Torrance shader is combined with a glossy reflection shader (left image). An environment is added to the reflectivity (center image), and an ambient occlusion node is used to modify the reflectivity (right image).

    Figure 10.26. The Cook-Torrance shader is combined with a glossy reflection shader (left image). An environment is added to the reflectivity (center image), and an ambient occlusion node is used to modify the reflectivity (right image).

    Figure 10.27 shows the shader network for this material.

    This gives you a basic idea of how to work with the mental ray base materials. Of course, you can make many more complex connections between nodes to create even more realistic and interesting surface materials. Experimentation is a good way to learn which connections work best for any particular situation.

  22. Save the scene as helmet_v04.ma. To see a version of the scene to this point, open the helmet_v04.ma scene from the chapter10scenes directory on the DVD.

The mental ray base shaders are connected to create a realistic painted metal surface for the helmet.

Figure 10.27. The mental ray base shaders are connected to create a realistic painted metal surface for the helmet.

Car Paint Materials

Simulating the properties of car paint and colored metallic surfaces is made considerably easier thanks to the special car paint phenomenon and metallic paint mental ray materials.

In reality car paint is made up of several layers; together these layers combine to give the body of a car its special, sparkling quality. Car paint uses a base-color pigment, and the color of this pigment actually changes hue depending on the viewing angle. This color layer also has thousands of tiny flakes of metal suspended within it. When the sun reflects off these metallic flakes, you see a noticeable sparkling quality. Above these layers is a reflective clear coat, which is usually highly reflective (especially for new cars) and occasionally glossy. The clear coat itself is a perfect study in Fresnel reflections. As the surfaces of the car turn away from the viewing angle, the reflectivity of the surface increases.

The metallic paint material is very similar to the car paint phenomenon material. In fact, you can re-create the car paint material by combining the mi_metallic_paint node with the mi_glossy_reflection node and the mi_bump_flakes node.

Using the Car Paint Material

In this exercise you'll apply the car paint material to the three-wheeled vehicle created by Anthony Honn.

  1. Open the carScene_v06.ma scene from the chapter10scenes directory on the DVD. This scene uses the Physical Sun and Sky network for lighting.

  2. Open the Hypershade window, and set the mode of the Create column on the left to Create mental ray Nodes. Expand the Materials section, and click on the mi_car_paint_phen_x shader (see Figure 10.28).

    The car paint materials are found in the Materials section of the Create mental ray Nodes column in the Hypershade.

    Figure 10.28. The car paint materials are found in the Materials section of the Create mental ray Nodes column in the Hypershade.

  3. Open the Outliner and select the carBody group; apply the mi_car_paint_phen1 material to this group. This group consists of the surfaces that make up the body of the car.

  4. Open the Attribute Editor for the mi_car_paint_phen1 material.

    The Diffuse Parameters section determines the color properties of the base pigment layer. As the color of this layer changes depending on the viewing angle, the various settings determine all of the colors that contribute to this layer.

  5. Set Base Color to dark navy blue; this is the main color of the base layer. If you wanted to add a texture map to apply decals to the car, you would use this channel.

  6. Set Edge Color to a similar shade of blue, but lower the Value so it is almost black. The Edge Color is apparent on the edges that face away from the camera. Newer cars and sports cars benefit from a dark Edge Color.

    Edge Color Bias sets the amount of spread seen in the Edge Color. Lower values (0.1 to 3) create a wider spread; higher values (4 to 10) create a narrower band of Edge Color.

  7. Lit Color is the color seen in the surface areas that face the light source. Set this color to a bright purplish-blue.

    Lit Color Bias works on the same principle as Edge Color Bias. Lower values (above zero) create a wider spread in the Lit Color.

  8. Diffuse Weight and Diffuse Bias set the overall strength of the Diffuse colors. A lower Diffuse Bias value (0 to 1) flattens the color; higher values (1 to 2) increase intensity toward the lit areas. Set Diffuse Bias to 2.

    The Specular Parameters settings define the look of the specular highlight on the surface. The highlight has two components: a bright center highlight and a surrounding secondary highlight. The Spec Glazing feature adds a polished shiny quality to the highlight, which works well on new cars. Turn this feature off when you want to create the look of an older car with a duller finish.

    Spec Weight and Spec Sec Weight are multipliers for the primary specular and secondary specular colors (respectively). Spec Exp and Spec Sec Exp determine the tightness of the highlight; higher values (30 and higher) produce tighter highlights. Generally Spec Sec Exp should be lower than Spec Exp.

    The Flake Parameters settings are the most interesting components of the shader. These determine the look and intensity of the metallic flakes in the pigment layer of the car paint.

    Flake Color should usually be white for new cars. Flake Weight is a multiplier for Flake Color; higher values intensify the look of the flakes; usually 1 is a good setting for most situations.

    Flake Reflect adds ray-tracing reflectivity to the flakes. This means that the flakes contribute to reflections of objects in the scene. For most situations a value of 0.1 is sufficient.

    Flake Exp is the specular exponent for the flakes. Much like Spec Exp, higher values create a tighter highlight.

    Flake Density determines the number of flakes visible in the paint. The values range from 0.1 to 10. In many situations a high value actually means that the individual flakes are harder to see.

    Flake Decay optimizes rendering times by setting a limit to the visibility of the flakes. Beyond the distance specified by this value the Flakes are no longer rendered, which can keep render times down and reduce render artifacts, especially if Flake Density is set to a high value.

    Flake Strength varies the orientation of the flakes in the paint. Setting this to 0 makes all the flakes parallel to the surface; a setting of 1 causes the flakes to be oriented randomly, making the flakes more reflective at different viewing angles.

    Flake Scale sets the size of the flakes. It's important to understand that the size of the flakes is connected to the scale of the object. If you notice that the size of the flakes is different on one part of the car than another part of the car, select the surface geometry and freeze the transformations so that the Scale X, Y, and Z values are all set to 1. This will correct the problem and ensure that the flakes are a consistent size across all the parts of the car.

  9. Set Flake Density to 0.6, Flake Strength to 1, and Flake Scale to 0.08.

    The Reflection Parameters settings are similar to those for the reflection parameters on the glossy reflection material. The reflectivity of the surface is at its maximum when Reflection Color is set to white. When this is set to black, reflections are turned off.

    Edge Factor determines the transition between the reflection strength at glancing angles and the reflection strength at facing angles.

    Reflection Edge Weight sets the strength of reflectivity at glancing angles, and Reflection Base Weight sets the reflectivity at facing angles. Generally the base weight should be lower than the edge weight to create a proper Fresnel reflection effect.

    Samples sets the sampling for glossy reflections. Unless you want to create glossy reflections, which are best used for older, duller cars, you can leave Samples at 0.

    Glossy Spread defines the glossiness of the reflections. Max Distance sets the point where reflection rays start sampling environment shaders and stop sampling the geometry in the scene.

    The Dirt Parameters settings allow you to add a layer of dirt to the surface of the car. Dirt Weight specifies the visibility strength of the dirt. For best results you can connect a painted texture map to Dirt Color if you want to add splashes of mud and grime.

  10. Set Edge Factor to 4, and leave the other settings at their defaults (see Figure 10.29).

    The settings for the car paint shader

    Figure 10.29. The settings for the car paint shader

    The car paint material is applied to the body of the car and rendered with the physical sun and sky lighting.

    Figure 10.30. The car paint material is applied to the body of the car and rendered with the physical sun and sky lighting.

  11. In the Render View window, create a test render from the renderCam camera (Figure 10.30).

  12. Save the scene as carScene_v07.ma. To see a finished version of the scene, open the carScene_v07.ma file from the chapter10scenes directory on the DVD.

The MIA Material

The MIA material is the Swiss army knife of mental ray shaders. It is a monolithic material, meaning that it has all the functionality needed for creating a variety of materials built into a single interface. You don't need to connect additional nodes into a specific network to create glossy reflections, transparency, and the like.

MIA stands for mental image architectural, and the shaders (mia_material, mia_material_x, mia_material_passes) and other lighting and lens shader nodes (mia_physicalsun, mia_portal, mia_exposure_simple, and so on) are all part of the mental images architectural library. The shaders in this library are primarily used for creating materials used in photorealistic architectural renderings; however, you can take advantage of the power of these materials to create almost anything you need.

The MIA material has a large number of attributes that at first can be overwhelming. However, there are also presets available for the material. You can quickly define the look you need for any given surface by applying a preset. Then you can tune specific attributes of the material to get the look you need.

Because of the physical-based nature of the materials, the dynamic range of their output can exceed what is visually pleasing on a standard computer monitor. To correct for this you can apply a lens shader to the rendering cameras to control the exposure. The lens shaders are explored later in the chapter. For this section, the exercise uses the Physical Sun and Sky network. When you add this network to a scene, the rendering cameras automatically have a lens shader applied, which means the materials will look correct when rendering.

In this section you'll get some practice working with the MIA material presets.

Using the MIA Material Presets

The presets that come with the MIA material are the easiest way to establish the initial look of a material. Presets can also be blended to create novel materials. Furthermore, once you create something you like, you can save your own presets for future use in other projects. You'll work on defining materials for the space suit helmet. This version of the scene uses the mia_physicalsunsky lighting network and Final Gathering to light the scene.

  1. Open the helmet_v05.ma scene from the chapter10scenes directory on the DVD. The surfaces in the model have been grouped by material type to make it easier to apply shaders.

  2. Open the Hypershade window, and set the mode of the Create column on the left to Create mental ray Nodes. Expand the Materials section, and click the mia_material_x button to create a material. Name the material metalShader.

  3. In the Outliner, select the helmetMetalSurfaces group, and apply the metalShader material to this group (right-click on the material in the Hypershade, and choose Assign mia_material_x1SG To Selection).

  4. Open the Attribute Editor for the metalShader. Click the Presets button in the upper right, and choose Copper

    Using the MIA Material Presets
  5. Open the Render View window, and create a render from the renderCam camera. It really looks like copper. Save the render in the render view.

  6. The material could use a little tweaking to make it look less like a kitchen pot. Click the Presets button again, and choose SatinedMetal

    Using the MIA Material Presets
  7. In the Attribute Editor, set Color to a medium grayish-blue (the color should be fairly unsaturated; otherwise the helmet will look very disco!). In the Reflection section, set Color to a light blue and turn on Metal Material—this adds a bluish tint to the reflections.

  8. Create another test render and compare it with the previous render (Figure 10.31).

    You can tweak many of the settings to create your own custom metal, but already it looks pretty good. The Glossiness setting adds blur to the reflections. Turning on Highlights Only creates a more plastic-like material—with this option activated the Reflection settings apply only to specular highlights.

  9. Next you can add chrome to the helmet. Create a new mia_material_x shader, and name it chromeShader. Select the chromeParts group in the Outliner, and apply the chromeShader to the group.

  10. Open the Attribute Editor for the chromeShader material. Click the Presets button, and apply the Chrome preset to the shader.

  11. Create another mia_material_x shader. Name it rubberShader. Apply this shader to the rubberParts group. Use the Presets button to apply the rubber preset.

  12. Create another test render and compare it to the previous renders.

    The rubber shader can use a little tweaking. A slight bump can increase the realism.

    The MIA material comes with a number of presets that can be blended together to create novel materials.

    Figure 10.31. The MIA material comes with a number of presets that can be blended together to create novel materials.

  13. Scroll down in the Attribute Editor, and click on the checkered box next to Standard Bump. In the Create Render Nodes pop-up, switch to the Textures tab, and select the Leather texture. The Attribute Editor opens to the leather node. Use the following settings (Figure 10.32):

    • Cell Color: light gray

    • Crease Color: dark gray

    • Cell Size: 0.074

    If the bump seems too strong, you can either adjust the cell and crease colors so that the shades of gray are closer together or switch to the Bump3D1 node and lower the Bump Depth value.

    When you use the mia_material_x shader, you have a choice of bump styles. When Standard Bump is enabled and No Diffuse Bump is activated, the bump appears only in the specular and reflective parts of the material, which can be useful for creating the look of a lacquered surface. Standard Bump works much like a typical bump shader on a standard Maya shader.

    The Leather texture is added as a bump to the rubber MIA material.

    Figure 10.32. The Leather texture is added as a bump to the rubber MIA material.

    The Overall Bump shader can be used for bump textures as well (the No Diffuse Bump setting has no effect on textures used for the Overall Bump shader); however, the Overall Bump slot is really intended for use with the mia_roundcorners texture. The mia_roundcorners texture adds a slight bevel to the edges of a surface in the render. This means you do not need to create beveled edges directly in the geometry. A very slight edge bevel can improve the realism of the model (sharp edges on surface are often a tell-tale sign that the object is computer generated). Let's take a look at the roundcorners texture in action by applying it to the chrome material. You can apply the roundcorners texture to the Overall Bump shader and another texture to the Standard Bump shader.

  14. In the Hypershade, select the chromeShader and open its Attribute Editor. Scroll down to the Bump section, and click on the checkered box to the right of Overall Bump. In the Create Render Nodes pop-up, switch to the mental ray tab and expand the Textures section. Click the Mia_roundcorners button to create this node.

  15. In the Attribute Editor for the mia_roundcorners1 node, set Radius to 0.1. Create another test render and compare it to the previous renders. You'll see that the chrome trim around the helmet has a light roundness to it, making it look a little more believable (see Figure 10.33, right image).

    Adding the mia_roundcorners texture to the chromeShader's Overall Bump channel creates a slight beveled edge to the geometry in the render (right image).

    Figure 10.33. Adding the mia_roundcorners texture to the chromeShader's Overall Bump channel creates a slight beveled edge to the geometry in the render (right image).

Creating Thick and Thin Glass and Plastic

Another feature of the mia_material shader is the ability to simulate thickness and thinness in the material itself without creating extra geometry. This can be very useful, especially for glass surfaces.

  1. In the Hypershade, create two new mia_material_x nodes. Name one thinGlass and the other thickGlass.

  2. Apply the thinGlass shader to the glassShield object in the Outliner. Apply the thickGlass material to the lampShields group in the Outliner.

  3. In the Attribute Editor for the thinGlass material, use the Preset button to apply the glassThin preset. In the Attribute Editor for the thickGlass shader, apply the glassThick preset.

  4. Create another test render.

    The thin glass of the face shield looks extremely believable, especially with regard to the shading on the inside of the helmet. The lamps at the top of the helmet have a chrome reflector behind the thick glass, which adds to the reflectivity of the material. The settings to control thickness are found under the Advanced Refractions controls. Along with the standard Index Of Refraction setting, there is an option for making the material either thin walled or solid. You also have the option of choosing between a transparent shadow and a refractive caustic that is built into the material (the caustics render when caustic photons are enabled and the light source emits caustic photons; for more information on caustics, consult Chapter 9).

  5. Open the Hypershade window, and create another mia_material_x node. Name this one plasticShader. Apply this shader to the plasticParts in the Outliner.

  6. Open the Attribute Editor for the plasticShader, and apply the translucentPlasticFilmLightBlur preset. Create another test render.

    This preset creates very translucent plastic using glossy refractions. In this situation it seems a little too transparent. Use the following settings to make the plastic look a little more substantial.

    • In the Diffuse section, set Color to a dim pale blue.

    • In the Reflection section, set Color to a dark gray, and set Glossiness to 0.35.

    • In the Refraction section, set Color to a dark blue and Glossiness to 0.52.

    • Scroll down to the Ambient Occlusion section, and activate Ambient Occlusion. Set Ambient Light Color to a light gray.

  7. Create another test render (see Figure 10.34).

  8. Save the scene as helmet_v06.ma. To see a finished version of the scene, open the helmet_v06.ma scene from the chapter10scenes directory on the DVD.

Apply the glass and plastic presets to parts of the helmet.

Figure 10.34. Apply the glass and plastic presets to parts of the helmet.

Other MIA Material Attributes

The ambient occlusion can be subtle on some materials, especially reflective material. This is because using Final Gathering creates a certain amount of ambient occlusion already. The Ambient Occlusion option on the material acts as a multiplier for existing ambient occlusion created by the indirect lighting (Final Gathering/Global Illumination). The Use Detail Distance option can be used to enhance fine detailing when set to On. When set to With Color Bleed, Ambient Occlusion factors the reflected colors from surrounding objects into the calculation.

The Translucency setting is useful for thin-walled objects, such as paper. This option works only when the material has some amount of transparency. The Translucency Weight setting determines how much of the Transparency setting is used for transparency and how much is used for translucency. So if Transparency is 1 (and the transparency color is white), and Translucency Weight is 0, the object is fully transparent (Figure 10.35, left). When Translucency Weight is at 0.5, the material splits the Transparency value between transparency and translucency (Figure 10.35, center). When Translucency Weight is set to 1, the object is fully translucent (Figure 10.35, right).

Three planes with varying degrees of translucency applied

Figure 10.35. Three planes with varying degrees of translucency applied

Translucency can be used for solid transparent objects to create a simple version of subsurface scattering; however, it is not as realistic as the misss shaders discussed in Chapter 11. Notice that you can also create translucent objects by experimenting with the glossiness in the Refraction settings. This can be used with or without activating the Use Translucency option.

The MIA materials have a wide variety of uses beyond metal and plastic. The materials offer an excellent opportunity for exploration. For more detailed descriptions of the settings, read the mental ray for Maya Architectural Guide in the Maya documentation.

Controlling Exposure with Tone Mapping

Tone mapping refers to a process in which color values are remapped to fit within a given range. Computer monitors lack the ability to display the entire range of values created by physically accurate lights and shaders. This becomes apparent when using HDRI lighting, MIA materials, and the physical light shader. Using tone mapping, you can correct the values to make the image look visually pleasing when displayed on a computer monitor.

Lens shaders are applied to rendering cameras in a scene. Most often they are used for color and exposure correction. You've already been using the mia_physicalsky lens shader, which is created automatically when you create the Physical Sun and Sky network using the controls in the Indirect Lighting section of the Render Settings window.

Using Exposure Shaders

The mia_exposure_photographic and mia_exposure_simple shaders are used to correct exposure levels when rendering with physically based lights and shaders. The mia_exposure_photographic lens shader has a lot of photography-based controls that can help you correct the exposure of an image. The mia_exposure_simple lens shader is meant to accomplish the same task; however, it has fewer controls and is easier to set up and use. In this exercise, you'll use the mia_exposure_simple lens shader to fix problems in a render.

The scene you'll use is the space helmet scene. This version of the scene uses the same mia_materials as the previous section. In the previous section the problems with the exposure were not noticeable because lens shaders were already applied to all the cameras when the Physical Sun and Sky network was created. In this section you'll learn how to apply the lens shader manually.

  1. Open the helmet_v07.ma scene from the chapter10scenes directory in the DVD. Currently this scene has no lighting. All the materials on the helmet are the same MIA materials described in the previous section.

  2. Open the Render Settings window, and switch to the Indirect Lighting tab. Click the Create button next to Image Based Lighting.

  3. In the Attribute Editor for the mentalrayibl1 node, click on the folder next to Image Name. Select the building_probe image from the chapter10sourceimages directory on the DVD. This is a typical, high-dynamic range image.

  4. Set Mapping to Angular. In the Render Stats section, turn off Primary Visibility so that the IBL sphere is not visible in the render.

  5. Enable Final Gathering in the Indirect Lighting tab of the Render View window, and set Accuracy to 200.

  6. Create a test render in the Render View window using the renderCam camera, and store the image in the Render View window.

    The rendered image looks very underexposed; the dark parts are very dark.

  7. In the Outliner, select the renderCam camera and open its Attribute Editor. Expand the mental ray section and click on the checkered box to the right of Lens Shader.

  8. In the Create Render Nodes window, switch to the mental ray tab, expand the Lenses section, and click the button labeled Mia_exposure_simple.

    This applies the mia_exposure_simple lens shader to the rendering camera. You need to remember to apply this shader to any of the cameras you'll use for rendering the scene.

  9. Create another test render from the renderCam camera. You'll see a big improvement in the image using the default settings of the mia_exposure_simple lens shader (see Figure 10.36).

  10. Save the scene as helmet_v08.ma. To see a finished version of the scene open the helmet_v08.ma scene from the chapter10scenes directory on the DVD.

    Following is a brief description of the shader's attributes.

    • Pedestal adds lightness to the black areas of the image; a negative value will "crush the blacks" by adding contrast to the image.

    • Gain increases the brightness of the lighter areas in the image.

    • The Knee value sets the point where overbright values (values that go beyond the 0–1 range) are brought down within the normal range.

    • The Compression setting applies compression to the overbright values as defined by the Knee setting.

    • Gamma applies the overall color correction to the image so it appears correct on the computer monitor. A typical value for Windows displays is 2.2. It's important to make sure that if you set the Gamma value in the lens shader, additional Gamma correction does not take place in the rendering and compositing pipeline.

For a more in-depth discussion of tone mapping, consult the mental ray for Maya Architectural Guide included in the Maya documentation.

The image on the left appears underexposed; adding a lens shader to control exposure fixes the problem, as seen in the image on the right.

Figure 10.36. The image on the left appears underexposed; adding a lens shader to control exposure fixes the problem, as seen in the image on the right.

Rendering Contours

mental ray has a special contour rendering mode that enables you to render outlines of 3D objects. This is a great feature for nonphotorealistic rendering. You can use it to make your 3D animations appear like drawings or futuristic computer displays. The end title sequence of the film Iron Man is a great example of this style of rendering.

Enable Contour Rendering

Rendering contours is easy to set up, but it requires activating settings in several different places.

  1. Open the carContour.ma scene from the chapter10scenes directory on the DVD. This scene shows the car modeled by Anthony Honn. A simple Lambert material is applied to the car.

  2. Open the Render Settings window, and select the Features tab. Expand the Contours section, and click Enable Contour Rendering. This makes contour rendering possible, but you won't see any results until you activate a few more options.

  3. Expand the Draw By Property Difference section. These settings define how the contours will be drawn. One of these options must be activated or contour rendering will not take place. Click Between Different Instances. This means lines will be drawn around each piece of geometry in the scene (see Figure 10.37).

    To render contour lines, you must check Enable Contour Rendering and choose a Draw By Property Difference option.

    Figure 10.37. To render contour lines, you must check Enable Contour Rendering and choose a Draw By Property Difference option.

  4. Open the Hypershade window, select the whiteLambert material, and graph its input and output connections. In the Work Area of the Hypershade, select the whiteLambertSG node that is attached to the whiteLambert shader, and open its Attribute Editor.

  5. In the Contours section of the mental ray rollout in the Attribute Editor, check the Enable Contour Rendering option. Set Color to red (Figure 10.38).

    Contour Rendering also needs to be enabled in the shader's shading group node settings.

    Figure 10.38. Contour Rendering also needs to be enabled in the shader's shading group node settings.

  6. Create a test render in the Render View window from the renderCam camera. The contours are added after the scene renders, on top of the shaded view of the geometry.

  7. Open the Render Settings window. In the Features tab, in the Contours section, activate Hide Source, and set Flood Color to a dark blue. Create another test render (see Figure 10.39).

This time the original geometry is hidden, and only the contours are rendered. Flood Color determines the background color when Hide Source is activated. Oversampling sets the quality and antialiasing of the contour lines.

You can adjust the width of the contours using the controls in the Contours section of the shading group. Absolute Width ensures that the contours are the same width; Relative Width makes the width of the contours relative to the size of the rendered image.

Since each shading group node has its own contour settings, you can create lines of differing thickness and color for all of the parts of an object. Just apply different materials to the different parts, and adjust the settings in each material's shading group node accordingly.

Contour rendering creates lines on top of the rendered surface. In the bottom image the source has been hidden so only the lines render.

Figure 10.39. Contour rendering creates lines on top of the rendered surface. In the bottom image the source has been hidden so only the lines render.

Experiment using different settings in the Draw By Property Difference section of the Render Settings window. More complex contour effects can be created by plugging one of the contour shaders available in the Create mental ray Node section of the Hypershade into the Contour Shader slot under the Custom Shaders section of the shading group node.

The Bottom Line

Use ambient occlusion.

Ambient occlusion describes the dark shadowing that occurs when ambient light rays are prevented from reaching part of a surface by another nearby surface. You can use the mib_amb_occlusion node in mental ray to fake the look of indirect lighting or augment the ambient occlusion shadowing that occurs when rendering with Final Gathering.

Master it

Create an ambient occlusion shader from a standard Maya shader.

Understand shading concepts.

Light rays are reflected, absorbed by, or transmitted through a surface. A rough surface diffuses the reflection of light by bouncing light rays in nearly random directions. Specular reflections occur on smooth surfaces; the angle at which rays bounce off a smooth surface is equivalent to the angle at which they strike the surface. Refraction occurs when light rays are bent as they are transmitted through the surface. A specular highlight is the reflection of a light source on a surface. In CG rendering this effect is often controlled separately from reflection; in the real world specular reflection and highlights are intrinsically related.

Master it

Create a standard Maya shader that is more reflective on parts of the shader that face away from the camera.

Apply reflection and refraction blur.

Reflection and Refraction Blur are special mental ray options available on many standard Maya shading nodes. You can use these settings to create glossy reflections when rendering standard Maya shading nodes with mental ray.

Master it

Create the look of translucent plastic using a standard Maya Blinn shader.

Use basic mental ray shaders.

The DGS and Dielectric shaders offer numerous options for creating realistic reflections and transparency. The mib (mental images base) shader library has a number of shaders that can be combined to create realistic materials.

Master it

Create a realistic CD surface using the mib shaders.

Apply the car paint shader.

Car paint consists of several layers, which creates the special quality seen in the reflections on car paint. The mi_carpaint_phen shader can realistically simulate the interaction of light on the surface of a car model. The diffuse, reflection, and metallic flakes layers all work together to create a convincing render.

Master it

Design a shader for a new and an old car finish.

Use the MIA materials.

The MIA materials and nodes can be used together to create realistic materials that are always physically accurate. The MIA materials come with a number of presets that can be used as a starting point for your own materials.

Master it

Create a realistic polished-wood material.

Control exposure using tone mapping.

Tone mapping corrects images that appear improperly exposed when rendering. This frequently occurs when HDRI lighting is used, when physical lights are used, and especially when physical lights are combined with MIA materials.

Master it

Create a scene that uses physical light shaders on the lights. Apply MIA materials to the objects in the scene, and correct the exposure using tone mapping.

scene. Adjust the settings on the lens shader to correct for exposure problems.

Render contours.

mental ray has the ability to render contours of your models to create a cartoon drawing look for your animations. Rendering contours requires that options in the Render Settings window and on the shading group for the object are activated.

Master it

Render the space suit helmet using contours.

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

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