A shader is a rendering node that defines the material qualities of a surface. When you apply a shading node to your modeled geometry, you use the shader’s settings to determine how the surface will look when it’s rendered. Will it appear as shiny plastic? Rusted metal? Human skin? The shader is the starting point for answering these questions. Shading networks are created when one or more nodes are connected to the channels of the shader node. These networks can range from simple to extremely complex. The nodes that are connected to shaders are referred to as textures. They can be image files created in other software packages or procedural (computer-generated) patterns, or they can be special nodes designed to create a particular effect.
The Autodesk® Maya® software comes with a number of shader nodes that act as starting points for creating various material qualities. The mental ray® plug-in also comes with its own special shader nodes that expand the library of available materials. Since the mental ray rendering plug-in is most often used to create professional images and animations, this book emphasizes mental ray techniques. You’ll learn how to use mental ray shaders to create realistic images.
In this chapter, you will learn to
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 organized in a way that the software understands. In Maya, the Hypershade provides you with a graphical user interface so that 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 throughout this book and the Maya interface. mental ray also uses shaders to determine properties for lights, cameras, and other types of render nodes. For example, special lens shaders are applied to cameras to create effects such as depth of field.
This section focuses on shaders applied to geometry to determine surface quality. 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. This section reviews these three concepts as well as other fundamentals that are important to understand before you start working with the shaders in a scene.
Diffusion describes how a light ray is reflected off 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 8.1).
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, the amount of diffusion is controlled by using the Diffuse slider. As the value of the Diffuse slider is increased, the surface appears brighter because it is reflecting more light back into the environment.
When a surface is perfectly 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 at 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 8.2).
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 diffuse the light rays completely. 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.
A transparent surface can change the direction of the light rays as they pass through the surface (see Figure 8.3). 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.
Shaders use a refractive index value to determine how refractions will be calculated. The refraction index is a value that describes the amount by 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 that the light rays are not bent. Glass typically has a refractive index between 1.5 and 1.6; water has a refractive index of 1.33.
If the refracting surface has imperfections, this can further scatter the light rays as they pass through the surface. This creates a blurry refraction.
The controls for refraction are found in the Raytrace Options 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 is named for the nineteenth-century French physicist Augustin-Jean 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 wall is perpendicular to your viewing angle, and thus the glancing angle is 0. If you are on the beach looking out 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 8.4).
Anisotropic reflections appear on surfaces that have directionality to their roughness, which causes the reflection of light to spread in one direction more than another. When you look at the surface of a compact disc, you see the tiny grooves that are created when data is written to the disc to create the satin-like anisotropic reflections. Brushed metal, hair, and satin are all examples of materials that have anisotropic specular reflections.
The resulting stretch or compression of an anisotropic reflection is defined in U and V directions. Anisotropy works in conjunction with the UV coordinates defined on a piece of geometry. (UV texture layout will be covered in Chapter 9, “Texture Mapping”.)
Layering shaders allow you to create a shader with infinite complexity. Autodesk Maya 2016 offers mental ray’s latest layering library, which includes its mila (mental image layering) shaders. The layering shaders are separate components of a traditional shader divided into separate nodes that can easily be stacked and blended on top of one another. The basic rule for using layering shaders is this: If you don’t need it, don’t include it. For instance, if you are creating a shader for a brick wall, there is no need to include transparency settings.
Layering shaders are considered physical-based shaders. Therefore, they should interact only with lights that are physically plausible; that is, the light should act like a real-world light. Area lights and image-based lighting work best with the layering shaders, since their visible light corresponds with the light that they actually cast. Other lights can be used, but the results may not be desirable.
The base layering shader is the mila material. It is created and assigned to geometry, as would be any other shader. When you create the mila material, a layer node and diffuse material are created automatically (see Figure 8.5).
From an artistic point of view, the mila material simply collects information from its layers. It does not contribute to the actual shading of the surface to which it’s assigned. With that, the mila material must always have a base component. By default, the base component is a diffuse layer. This is comparable to a Lambert shader. There are three variations of base components: diffuse, reflective, and transmissive or translucent (see Figure 8.6). You can change the base component at any time without affecting added layers.
Layers are added from within the mila material. Each layer is weighted. Its effect over bottom layers can be reduced by decreasing the layer’s weight. After adding your first layer, you have the option to add a mix layer. Mix layers blend the layer components in an additive manner. For instance, mixing two diffuse layers, one red and one blue, would result in a purple diffuse shader.
A layer’s directional weight can be controlled through three different layer types: Weighted, Fresnel, or Custom. These options are available when you create a new layer. The directional weight of a layer controls how light interacts with that layer. Choosing a type sets specific options in the layer node. Weighted is the plain version of the layer without any directional weight. Fresnel uses the index of refraction (IOR) value established in the layer. Custom allows you to define your own normal and grazing reflectivity. Regardless of the type of layer you choose, you can always change the settings after the layer has been created, but the attributes will work only with the appropriate layer type.
You can add as many components as you want to a single layer. You can also create multiple layers and connect them to a single layer, combining the effects from every component. Layering shaders are extremely versatile and unrestricted. In the next chapter, you’ll create a layering network with subsurface scattering components to give a lifelike appearance to a giraffe model.
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. However, turning these options on does not make the shader physically correct. They can also take a while to render. By using a mila shader, you can optimize your shading network and achieve a more realistic look.
Reflection is easy to use, and it helps make objects look photo real. This exercise demonstrates how to add reflection and roughness to a surface using mila shaders. This scene contains a model of a coffeemaker above a checkered ground plane.
reflections_v01.ma
file from the chapter8scenes
folder at the book’s web page (www.sybex.com/go/masteringmaya2016
).mila_glass_MAT
.
Under the Base rollout, in the Property Editor, choose black for the color.
0.2.
The Roughness defines microscopic variations in the surface, causing the light that hits it to bounce off in different directions. Ultimately, this creates a blurring effect (see Figure 8.9).reflections_v02.ma
.Many surfaces are more reflective than you may realize. An unpolished wooden tabletop, or even asphalt, can have a small amount of reflection. Adding a low reflectivity value plus reflection blurring to many surfaces increases the realism of the scene.
Refractions cause the light passing through a surface to bend in different directions. The refraction component works just like the reflection component. Adding roughness causes microscopic variations in the surface. As a result, it can cause distortion and blurring of the objects that appear behind a transparent surface. The following exercise continues where the previous one left off.
reflections_v02.ma
file from the chapter8scenes
folder at the book’s web page (www.sybex.com/go/masteringmaya2016
).0.7
.0.7
to increase the amount of blur. Figure 8.10 shows the results.0.2
. The result is shown in Figure 8.12.refractions_v01.ma
.To see a version of the scene, open the refractions_v01.ma
file from the chapter8scenes
folder at the book’s web page.
In this exercise, you’ll work on defining materials for the coffeemaker. The chapter8
eference
folder at the book’s web page contains a photo of the appliance to help you match the look. The example scene uses the Physical Sun and Sky lighting network and Final Gathering to light the scene.
coffeeMaker_v01.ma
scene from the chapter8scenes
folder at the book’s web page. The surfaces in the model have been grouped to keep the model organized.brushedAluminum_MAT
.1.0
and the Roughness to 0.3
. Use an HSV Color value of 0.6
.0.1
.You can tweak many of the settings to create your own custom metal, but it already looks pretty good. Next, you can add a black plastic material to various parts of the coffeemaker:
shinyBlackPlastic_MAT
.0.2
and the layer’s Color to black
.coffeeMaker_v02.ma
.To see a version of the scene, open the coffeeMaker_v02.ma
scene from the chapter8scenes
folder at the book’s web page.
Some areas of the coffeemaker’s control panel are not brushed aluminum. Several polygon faces for the digital readout should have different shaders assigned to them. The following exercise demonstrates applying a shader to these areas:
coffeeMaker_v02.ma
scene from the chapter8scenes
folder at the book’s web page.readout_MAT
.68.571
0.167
0.329
coffeeMaker_v03.ma
.To see a version of the scene, open the coffeeMaker_v03.ma
scene from the chapter8scenes
folder at the book’s web page.
In reality, car paint consists of several layers; 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 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.
In this section, you’ll learn how to use the car paint material by applying it to a model of a truck.
Open the truck_v01.ma
scene from the chapter8scenes
folder at the book’s web page. This scene uses the Physical Sun and Sky network for lighting.
carPaint1_MAT
.carPaint1_MAT
from the Hypershade. Choose the Input and Output Connections icon to graph the material’s connections in the Hypershade Node Editor (see Figure 8.18).At the top of the attributes, you’ll find the Base rollout. The settings here determine 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.
0.6
. If you wanted to add a texture map to apply decals to the car, you would use this channel. Figure 8.19 shows a render of the truck so far.Set Edge Color to a similar shade of red, but lower the value so that it is almost black. Edge Color is apparent on the edges that face away from the camera. Newer cars and sports cars benefit from a dark Edge Color setting.
Edge Color Bias specifies the amount of spread seen in Edge Color. Lower values (0.1 to 3) create a wider spread; higher values (4 to 10) create a narrower band of Edge Color.
10.0
. Figure 8.20 shows the rendered results.360.0
0.421
0.348
0.2
0.001
0.4
0.1
You can see the rendered version with the new Flake settings in Figure 8.21.
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 A multiplier for Flake Color. Higher values intensify the look of the flakes; 1 is usually a good setting for most situations.
Flake Roughness Changes the shader from a typical Lambert-style shading at 0 to a more powdery look at 1.0.
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 compared to the others, 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 of the parts of the car.
Flake Density Determines the number of flakes visible in the paint. The values range from 0.0 to 1.0. In many situations, a high value means that the individual flakes are harder to see.
Flake Strength Varies the orientation of the flakes in the paint. Setting this to 0 makes all of 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 Type Specifies different procedural patterns to define the shape of the flakes.
Flake Cell Style Forces the pattern specified in the Flake Type setting to be represented as irregular shapes or circles.
Flake Circle Size Increases or decreases the size of the circular pattern if Circular is chosen for the Flake Cell Style value.
A specular layer defines the look of the specular highlight on the surface. By adding a specular layer, you can make the car paint look brand-new or old and dull.
1.44
to match the IOR of aluminum. Figure 8.22 shows the rendered results.The reflectivity of the surface is at its maximum when Reflection Color is set to white. When this option is set to black, reflections are turned off.
1.44
.0.0
. Figure 8.23 shows the results of the glossy layer.truck_v02.ma
.To see a finished version of the scene, open the truck_v02.ma
file from the chapter8scenes
folder at the book’s web page.
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 Make a standard Blinn shader appear like glass refracting light in the
jellybeans_v01.ma
scene in thechapter8scenes
folder on the book’s web page.
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.
Understand mila shading layers. The layering shaders are separate components of a traditional shader that can easily be stacked and blended on top of one another. Layered shaders allow you to add an infinite amount of detail to a single shader.
Master It Create a mix layer and blend two colored diffuse layers together.