Using Expressions

Maya expressions offer the most efficient and powerful way to incorporate math calculations into a custom shading network. although a deeper discussion on expressions is beyond the scope of this book, here are a few items to keep in mind: " Create New Expression Right-clicking an attribute field in the Attribute Editor and p choosing Create New Expression from the shortcut menu opens the Expression Edi-

p tor window. The attribute that was chosen will be highlighted in Expression Editor's x Attributes list. Once a valid expression is created and the Create button is clicked, an

^ expression node and appropriate connections are created. The attribute field, as seen g in the Attribute Editor, turns purple to indicate the connection to an expression. The m expression node is not immediately visible in the Hypershade work area. However, if g you select the node to which the expression was applied in the work area and click the x Input And Output Connections button, the expression node is revealed.

  • Time A master Time node (timel) is automatically connected to each expression node
  • and is undeletable. This node manages the flow of time for the Maya Timeline. You
  • can connect the node's outTime to any single attribute of any node; however, a con-

1 nection line will not necessarily appear in the Hypershade window.

Nodes and Channels You can reference any channel of any node in an expression. The naming convention will always follow the formula node.channel. Functions For a list of Maya math, vector, array, and other functions available to expressions, choose the Insert Functions menu of the Expression Editor window. Duplication You can duplicate expression nodes by choosing Edit > Duplicate > Without Network from the Hypershade window menu. The new expression appears in the Expression Editor if you choose Select Filter > By Expression Name from the Expression Editor menu. The math functions of the duplicate are identical to the original. However, the channel names are missing. You can display the new expression node by entering the node name, such as expression3, into the search field of the Hypergraph Connections window.

Changing the Range of a Value

The Set Range utility maps one range of values to a second range of values. The underlying math for the utility follows:

outvalue = Min + (((value-oldMin)/(oldMax-oldMin)) * (Max-Min))

As an example illustrated by Table 8.1, five different ValueX inputs are processed by a Set Range utility, resulting in new Out ValueX outputs. For this example, Old MinX of the utility is set to -100, Old MaxX is set to 100, Min X is set to 0, and MaxX is set to 1.

Table 8.1 The Result Of Various ValueX Inputs Applied To A Set Range Utility

ValueX

-100

-75

0

21

500

Out ValueX

0

0.125

0.5

0.605

1

The mid-value of the Old MinX and Old MaxX range (0) becomes the mid-value of the new MinX and MaxX range (0.5). Any value greater than the Old MaxX is clamped to the Old MaxX value before it is remapped. Hence, 500 becomes 100, which is then remapped to 1. Min, Max, Old Min, Old Max, and Value are vector 239

attributes. The individual channels (for example MinX, MinY, MinZ) can carry dif- ^

ferent values. T

In a working example, the Set Range utility is used to create diffuse shad- T

ows on a directional light. Diffuse shadows are a product of diffuse lighting. A diffuse T

light source is one that either produces divergent light rays or is physically large enough S

that it produces multiple overlapping shadows. One feature of a diffuse shadow is an increased edge softness over distance. A second feature is a shadow color that becomes lighter over distance (see the photo at the top of Figure 8.5).

Since depth map shadows are calculated using a single point-of-view of a light, Maya is unable to produce a diffuse effect. A light's Filter Size attribute blurs the edge of a depth map shadow, but the blur is equally intense whether or not it's close to the object casting the shadow. Raytraced shadows, on the other hand, can be adjusted to have a larger spread and thus a softer edge over distance; however, high-quality raytrace shadows can be time intensive. (See Chapter 3 for more information on shadow quality settings.) Nonetheless, you can emulate diffuse shadows with the shading network illustrated in Figure 8.5. To view this custom shading network, follow these steps:

  1. Open the setrange_shadow.ma file from the CD. Open the Hypershade window and switch to the Lights tab.
  2. MMB-drag the KeyShape node into the work area.
  3. With KeyShape selected, click the Input And Output Connections button. The network becomes visible.
Maya Hypershade Utilities

Figure 8.5 The diffuse quality of a depth map shadow is controlled by a Set Range utility. This scene is included on the CD as setrange_shadow.ma.

oo a

Figure 8.5 The diffuse quality of a depth map shadow is controlled by a Set Range utility. This scene is included on the CD as setrange_shadow.ma.

For the 3D render at the bottom of Figure 8.5, a directional light named Key is placed behind a polygon cube. The light's Use Depth Map shadows attribute is checked. Two locators are placed in the scene. the first locator, named shadow_begin, is placed at a point on the ground where the shadow begins (close to the cube). a second locator, named shadow_end, is placed on the ground where the shadow ends.

Note: To accurately position a locator at the point where a shadow ends, select the shadow-casting light and choose Panels > Look Through Selected from a workspace view menu. The locator will be occluded by an object if it is within a shadow.

The center attribute of the shadow_begin transform node is connected to the pointl of a distanceBetween node (distanceBetweenB). The center of shadow_end is connected to point2 of distanceBetweenB. The Center attribute provides the location of an object's bounding box in world space. Ultimately, distanceBetweenB determines the length of the shadow. The center of shadow_end is also connected to the point2 of a second distanceBetween node (distanceBetweenA). The pointWorld attribute of a samplerlnfo node is connected to the pointl of the distanceBetweenA. The Point world attribute stores the world position of the point being sampled during the render. Hence, distanceBetweenA determines the distance between the end of the shadow and the point being sampled. The distance of distanceBetweenA is connected to the inputX of a reverse node (reverseA). The outputX of the reverseA is connected to the valueX and valueY of a setRange node.

In the meantime, the distance of the distanceBetweenB node is connected to its own reverse node (reverseB). The outputX of reverseB is connected to oldMinX and oldMinY of the setRange node. The setRange node's MinX is set to 2 and its MaxX is set to 32. This represents the range of values that can be used as a Filter Size for the directional light. Since the Old Min value is fed by distanceBetweenB, and has been made negative by reverseB, the Old Max is set to 0. This negative range (-n to 0) ■

matches the negative distance value provided by reverseA. These negative values are A

necessary to place the diffuse effect at the shadow end and not the shadow beginning. H U

In this case, if a point near the end of the shadow is sampled, the distance between l that point and the shadow_end is small and outputX of reverseA will be a small nega- 1

tive number (for example, -1). As a number, -1 is relatively high in the Old Min and Old Max range (close to 0) and is thus remapped to a number close to 32. Again, distanceBetweenB and reverseB represent the length of the shadow and therefore supply the Old Min values. If a point near the beginning of the shadow is sampled, the distance between that point and the shadow_end is large and outputX of reverseA will be a large negative number, such as -15. As a number, -15 is relatively low in the Old Min and Old Max range (not close to 0) and is thus remapped to a number close to 2.

Returning to the network, the outValueX of the setRange node is connected to the dmapFilterSize of the directional light KeyShape node. A dmapFilterSize of 0 produces no additional blur. A dmapFilterSize value of 32 creates the maximum amount of blur on the shadow. The outValueY of the setRange node is also connected to the shadColorR, shadColorG, and shadColorB of the light KeyShape node. The MinY of the setRange node is set to 0 and the MaxY is set to 0.5. This converts the Old Min and Old Max range into a range usable as a color. The end effect is a shadow that becomes lighter as it travels farther away from the cube. Increasing the value of MaxY will create a lighter shadow. This network works best with depth map shadows that have a relatively large Resolution value (for example, 1024). Smaller Resolution values will reveal the transitions between different Filter Size values. Nevertheless, this offers an alternative way to produce a diffuse shadow effect without the necessity of potentially time-consuming raytracing.

Mapping Per-Particle Attributes

The Array Mapper utility is designed to control per-particle attributes on particle nodes. the attributes can affect particle size, dynamic behavior, color, and opacity. ^n array is an ordered list of values.)

the simplest way to see the array Mapper utility work is to create an RGB PP attribute for hardware-rendered particles. since the process is a little unusual, I recommend you use the following steps:

  1. Create a new scene. switch to the Dynamics menu set and choose Particles > Create Emitter. Play back the timeline. select the resulting cloud of particles.
  2. open the attribute editor tab for a selected particle shape node (particle-shape1) and expand the Lifespan attributes section. set the Lifespan Mode value to either Constant or random range and choose a lifespan length (measured in seconds).
  3. Click the Color button in the add Dynamic attributes section. the Particle Color window opens. Check the add Per Particle attribute option and click the add attribute button (see Figure 8.6). this adds an RGB PP attribute to the list in the Per Particle (array) attributes section of the particle shape node's attribute editor tab.

oo d

Figure 8.6 (Left) The Particle Color window. (Right) The Per Particle (Array) Attributes and Add Dynamics Attributes sections of a particle shape node's Attribute Editor tab. Note the addition of the RGB PP attribute.

4. right-click the field next to RGB PP and choose Create ramp from the shortcut menu. a Particle array utility and a ramp texture are automatically connected to the particle shape node. the particles will then pick up the color of the ramp over their lifespan. You can render the default point particles with either the Maya Hardware renderer or the Hardware render Buffer. (see Chapter 10 for more information on hardware rendering.)

You can manually connect the Array Mapper utility (found in the general Utilities section of the Create Maya Nodes menu). for example, in figure 8.7 the outColor of a ramp texture node is connected to the computenodeColor of an array-Mapper node. the message of the ramp is also connected to the computeNode of the arrayMapper. The outColorPP of the arrayMapper node is connected to the rgbPP of the particleshape node. In turn, the ageNormalized of the particleshape node is connected to the vCoordPP of the arrayMapper node. the Min Value and Max Value attributes of the Array Mapper utility serve as a clamp for the outColorPP and out-ValuePP attributes (outValuePP is the single-attribute version of outColorPP). You can replace the ramp texture with other types of textures, but the results will be unpredictable.

OUtColor rabPP I pariieieSheos

OUtColor rabPP I pariieieSheos

computeNodeColor

Figure 8.7 The shading network for a per-particle attribute

Although color is used in the previous example, a number of other per-particle M

a attributes are available, including incandescencePP, radiusPP, and opacityPP. You can H

access these attributes by clicking the General button in the Add Dynamics Attributes i section of the particle shape's Attribute Editor tab and choosing the Particle tab of the t

Add Attribute: particleshape window (see Figure 8.8). in addition to the PP attributes, s the Particle tab carries a long list of more esoteric attributes, any of which can be utilized for per-particle operations through an expression.

■(¿k Add Attribute: partideShapel

Help

New Particle

Control collisionWorldF'oiition coiorAccum goalOffset goalU

goalV

goaiWeightOPP

goaWeightl PP

goaWeight2PP

goalWeight3PP

goaf\Veight4PP

incandescence incandescencePP

lineWidth multiCount multi Radius

1 OK |

Add

Cancel

The Particle tab of the Add Attribute window. Only a small portion of the available PP attributes are shown.

In a second example, a single Array Mapper utility drives the color, opacity, and acceleration of a point particle node (see Figure 8.9).

oo a

Maya Array Mapper
Figure 8.9 A point particle node receives its color, opacity, and acceleration from an Array Mapper utility. This scene is included on the CD as array_point.ma. A QuickTime movie is included as array_point.mov.

To view the shading network, follow these steps:

  1. open the array_point.ma file from the CD. open the Hypershade window and switch to the Textures tab.
  2. MMB-drag the ramp node into the work area.
  3. with the ramp node selected, click the input and output Connections button. The network becomes visible.

with this network, the Noise attribute of the connected ramp node is set to 1 and its noise freq attribute is set to 50, which creates a random pattern throughout the ramp. although rgbPP receives its color directly from the ramp node, an expression controls the particle node's opacity, acceleration, and lifespan. the expression follows:

  1. opacityPP=arrayMapper.outVa1uePP;
  2. acce1eration=arrayMapper.outVa1uePP*-500;
  3. 1ifespanPP=rand(1,3);

To view the expression, follow these steps:

  1. Choose window > animation Editors > Expression Editor.
  2. Choose select filter > By expression name from the expression editor menu. Click the word particleShape in the objects field.
  3. switch the Particles attribute to Creation. The expression code is revealed in the text field at the bottom of the window.

In the first line of the expression, outValuePP of the arrayMapper node drives opacityPP. In the second line of the expression, outValuePP drives the particle's acceleration attribute. The acceleration attribute controls the rate of velocity change on a per-particle basis (although it's not listed as a "PP"). You can see the effect of the variable acceleration if the particle count is reduced to a low number. Some particles move rapidly, while others fall very slowly. The outValuePP is multiplied by -500, which makes the acceleration more rapid and the particles' direction in the negative X, Y, and Z direction. The ability to use outValuePP as an input for multiple particle attributes eliminates the need for additional arrayMapper and ramp nodes.

In the third line of the expression, the particle lifespan is assigned a random number from 1 to 3 with the rand() function. The outValuePP attribute is automatically connected to input[0] of the arrayMapper node; this represents the use of outValuePP in an expression. When an expression is created for a per-particle attribute, the expression is carried by the particle shape node and no separate expression node is generated.

Note: Right-clicking an attribute field in the Per Particle (Array) Attributes section of a particle shape node's Attribute Editor tab provides the Creation Expression option in a shortcut menu. Creation Expression opens the Expression Editor and lists the particle shape and its numerous channels in the editor's Attributes list. Using the Creation Expression option is also a quick way to access preexisting per-particle expressions.

Creation expressions are executed at the start time of an animation. They are not executed as the ani- N I ^

mation plays. When using particles, a creation expression is applied one time per particle at the frame in which the particle is born. In contrast, a runtime expression executes at each frame during playback. A runtime expression is useful when values need to constantly change over the life of an animation. You can create a runtime expression by right-clicking an attribute field in the Per Particle (Array) Attributes section of a particle shape node's Attribute Editor tab and choosing Runtime Expression Before Dynamics or Runtime Expression After Dynamics.

As for other particle settings, the emitter is set to a cube volume shape with 0, -1, 0 Direction values. A turbulence field with a Magnitude value of 500 is also assigned to the particles. The field adds additional random motion; although the turbulence affects direction, it does not impact the overall acceleration. The end result is a glitter-like fall of particles. The point particles are rendered with the Hardware Render Buffer with Multi-Pass Rendering.

Unfortunately, the Array Mapper utility will not work with software-rendered particles—unless it is used in conjunction with a Particle Sampler utility. The Particle Sampler utility serves as a go-between, retrieving attribute information from a particle shape node and passing it on to a material assigned to the software-rendered particles. For example, in Figure 8.10 the example from Figure 8.9 is reused with the addition of a Particle Sampler utility. The Particle Render Type of the particle shape node is switched to Blobby Surface. The particle node is assigned to a blinn material node. The Noise value of the original ramp texture node is reduced and the ramp colors are adjusted. The Rate(Particles/sec) value of the particle node is reduced for easier viewing. a directional light is added to the scene.

I Moie Read-Only Scalar Attribute*

Age Normalized ¡0.000 Colot Red [0.QÜD Color Green 10.000 Color Blue ¡0.000 Opacity PP ¡0.000 Opacity ¡0.000 Particle Id [d Final Lifespan PP

Lifespan PP |0.000

Lifespan |0.000

Age ID. 000 Birth Time |0.000

Parent U |0.000

Parent V |0.000 Collision 0 |D.500

Collision V 10.500

Radius PP |0.000

Radius |0 000

I Moie Read-Only Scalar Attribute*

Age Normalized ¡0.000 Colot Red [0.QÜD Color Green 10.000 Color Blue ¡0.000 Opacity PP ¡0.000 Opacity ¡0.000 Particle Id [d Final Lifespan PP

Lifespan PP |0.000

Figure 8.10 A Blobby Surface particle node receives its color, opacity, and acceleration through Array Mapper and Particle Sampler utilities. This scene is included on the CD as array_b1obby.ma. A QuickTime movie is included as array_b1obby.mov.

oo d

Aside from these adjustments, all the old network connections and the old expression are intact. As an addition, the rgbPP of a particlesamplerlnfo node is connected to the color and the ambientColor of the blinn. the opacityPP of the particlesamplerlnfo node is also connected to the transparencyr, transparencyG, and transparencyB of the blinn. the end result is a color distribution, opacity, lifespan, and acceleration roughly identical to Figure 8.9 but with a software-rendered particle node. the Particle sampler utility also carries a long list of read-only attributes (see the left side of figure 8.10). these attributes remotely read attribute information from the particle shape node that is assigned to the material. (for this to work, the material must share the shading network with the Particle sampler utility.) the attributes are intuitively named (for example, particlesamplerlnfo.rgbPP remotely reads particle-shape.rgbPP). You can connect these attributes to any attribute of a material that may prove useful.

Note: You can change various per-particle attributes, such as lifespanPP and opacityPP, through the Particles tab of the Component Editor (Window > General Editors > Component Editor). You can select particle nodes in a workspace view by clicking the Select By Object Type: Dynamics button in the Status Line toolbar. You can select particles individually by clicking Select By Component Type: Points in the Status Line toolbar.

Note: Not all per-particle attributes will work with all particle render types. For instance, radiusPP will only work with Blobby Surface, Cloud, and Sphere particles. For a detailed attribute list, see "List of Particle Attributes" in the Maya help file.

Note: If particles are emitted from a NURBS or polygon object, they can derive their color from

that surface. See the "Use a Texture to Color Emission or Scale the Rate" tutorial in the Maya help file. Working with Vectors and Matrices

Vectors are useful for determining direction within Maya. Matrices, on the other hand, are an intrinsic part of 3D and are necessary for converting various coordinate spaces. Comparing the direction of lights, cameras, and surface components within different coordinate spaces can provide information useful for custom shading networks. Before I discuss such networks, however, a review of vector math, the Vector Product utility, and Maya matrices is warranted.

Understanding Vector Math

In the mathematical realm, a vector is the quantity of an attribute that has direction as well as magnitude. For instance, wind can be represented by a vector since it has direction and speed (where speed is the magnitude).

In Maya, there are several variations of vectors. Vector attributes are simply a related group of three floating-point numbers. Color is stored as a vector attribute (R, G, B). At the same time, Maya vector attributes are used for transforms in 3D space. For instance, the translate of an object is represented as a vector attribute (X, Y, Z).

A second variation of a Maya vector is used to determine direction. That is, a particular point in space (X, Y, Z) has a measurable distance from the origin (0, 0, 0) and a specific angle relative to the origin. In this case, the distance serves as the vector magnitude and the angle is the vector direction. There are a number of specialized attributes that provide this style of vector (which can be loosely described as a "spatial vector"). A more detailed description of commonly used spatial vectors follows: Normal Camera and Surface Normal The Normal Camera attribute is provided by the Sampler Info utility and material nodes. It represents the surface normal of the point being sampled in camera space. A surface normal is a vector that points directly away from the surface (and at a right angle to the surface). In general, surface normals are normalized so that their length (that is, their magnitude) is 1.

Ray Direction The Ray Direction attribute is provided by the Sampler Info utility and material nodes. It's a vector that runs from the surface point being sampled to the camera in camera space.

Facing Ratio The Facing Ratio attribute is uniquely provided by the Sampler Info utility and is the cosine of the angle between Ray Direction and Normal Camera. (A cosine is the trigonometric function often defined as the ratio of the length of the adjacent side to

that of the hypotenuse in a right triangle.) The Facing Ratio is clamped between 0 and 1. A value of 0 indicates that the surface normal is pointing away from the camera. A value of 1 indicates that the surface normal is pointing toward the camera. Light Direction The Light Direction attribute is provided by the Light Info utility and is a vector that represents the direction in which a light, camera, or other input node is pointing in world space. Lights also have a built-in Light Direction attribute (found in the Light Data section of the light shape node's Connection Editor attribute list). However, the Light Direction attribute of a light is in camera space.

Using the Vector Product Utility

The Vector Product utility accepts any vector attribute, whether it is a color, a transform, or a spatial vector. You can set the utility's Operation attribute to one of four modes:

Dot Product Dot Product multiplies two vectors together and returns a value that represents the angle between them. Its output may be written as output = (a*d) + (b*e) + (c*f)

The first input vector is (a, b, c) and is connected to Input 1 of the utility. The second £ input vector is (d, e, f) and is connected to Input 2 of the utility. The output is a single f-h

3 value. If Normalize Output is checked, the output is the actual cosine and will run

5 between -1 and 1. -1 signifies that the vectors run in opposite directions. 0 signifies x h that the vectors are perpendicular to each other. 1 signifies that the vectors run in the

  • same direction. When the Operation attribute is set to Dot Product, outputX, outputY,
  • and outputZ attributes are the same value.

o Cross Product Cross Product generates a third vector from two input vectors. The new

« vector will be at a right angle (perpendicular) to the input vectors.

o Vector Matrix Product and Point Matrix Product Vector Matrix Product converts the coordinate z

£ space of a vector. This becomes useful when input vectors are in different coordinate z spaces, such as camera and world. For conversion to work, the utility requires the con-

x nection of a transform matrix to its Matrix attribute. You can connect the XForm Matrix oo attribute of a camera or geometry transform node for this purpose. Xform Matrix

™ is a world space matrix. Maya nodes also carry the World Matrix attribute, which is in

< world space. (For examples of shading networks using World Matrix, see Chapter 7.)

u The vector that requires conversion is connected to the Input 1 attribute. The Point Matrix Product operation offers the same space conversion, but operates on points.

An Overview of Maya Matrices

Maya uses a 4 x 4 matrix for transformations (see Figure 8.11). The position of an object is stored in the first three numbers of the last row. The object's scale is stored as a diagonal from the upper left. The object's rotation is indirectly stored within the first three vertical and horizontal positions from the upper-left corner; the rotation values are stored as sine and cosine values. when an object is created, or has the Freeze Transformations tool applied to it, its transform matrix is an identity matrix. An identity matrix is one that produces no change when it is multiplied by a second transform matrix. In other words, an object with an identity matrix has no translation, rotation, or increased/decreased scale.

tx ty tz 1

Figure 8.11

Maya's 4 x 4 transformation matrix

Converting Camera Space to World Space

As an example of camera space to world space conversion, in figure 8.12 the Xform Matrix of a polygon cube is used to convert a Normal Camera vector of a sampler Info utility into a world space vector. The results are illustrated by applying the resulting vector to the color of a material.

Figure 8.12 The Xform Matrix attribute of a polygon cube drives the color of a material. This scene is included on the CD as xform_matrix.ma. A QuickTime movie is included as xform_matrix.mov.

The xformMatrix of the pCubel transform node is connected to the matrix of a vectorProduct node. (pCubel is the small gray cube in Figure 8.12.) The normalCamera of a samplerlnfo node is connected to the inputl of the vectorProduct node. The vectorProduct Operation value is set to Vector Matrix Product. The output of the vectorProduct node is connected directly to outColor of a surfaceShader material node, which is assigned to a second, larger polygon shape.

As a result of the custom connections, the faces of the larger shape that point toward the camera render blue until pCubel is rotated. This is a result of the Normal Camera attribute existing in camera space. A normal that points directly toward the camera always has a vector of 0, 0, 1. At the same time, while pCubel is at its rest position, its xformMatrix is an identity matrix and has no effect on the normalCamera value. Thus, the values 0, 0, l are passed to outColor of the surfaceshader node. When pCubel is rotated, however, the normalCamera value is multiplied by the new xformMatrix and hence the color of the shape is affected. For instance, if pCubel is rotated -45, -45, 0, a pale green results on the faces of the larger shape that point toward camera. The resulting math is illustrated in Figure 8.l3.

Normal Camera vector Xform Matrix Vector Matrix Product result

0 0 0 1

  • 0 1 ^ I-.5:7101 = [-5 7 5
  • 0 .7 .5 RGB)

gs Figure 8.13 A matrix calculation based on pCubel's rotation of -45, -45, 0.

& The matrix numbers have been rounded offfor easier viewing.

o When representing the matrix calculation, as with Figure 8.l3, the extra

£ number l at the right side of the Normal Camera vector (and at the bottom-right z corner of the Xform Matrix) is necessary for this type of math operation; however, x these numbers do not change as the corresponding objects go through various oo transformations.

e _ Note: As with many custom networks, the material icon in the Hypershade window, as well as the workspace view, may not provide an accurate representation of the material. To see the correct result for the previous example, use the Render View window.

Note: You can retrieve the current Xform Matrix value of a node by typing getAttr name_of_ node .xformMatrix; in the Script Editor.

Testing a Condition

The Condition utility functions like a programming If Else statement. If Else statements are supported by Maya expressions and are written like so: if ($test < 10){

print "This Is False";

If the $test variable is less than 10, Maya prints "This Is True" on the command line. The If Else statement serves as a switch of sorts, choosing one of several possible outcomes depending on the input. The function of the Condition utility, when written in the style of an If Else statement, would look like this: if (First Term Operation Second Term){

Color If False;

First Term and Second Term attributes each accept a single input or value, a while the Color If True and Color If False attributes accept vector values or inputs. H

The Operation attribute has six options: Equal, Not Equal, Greater Than, Less Than, I

Greater Or Equal, and Less Or Equal. I

With the Condition utility, you can apply two different textures to a single sur- s face. By default, all surfaces in Maya are double-sided but only carry a single UV texture space. Hence, a plane receives the same texture on the top and bottom. You can avoid this, however, with the shading network illustrated by Figure 8.14.

The flippedNormal of a samplerlnfo node is connected to firstTerm of a condition node. The Flipped Normal attribute indicates the side of the surface that is ren-derable. If the attribute's value is 1, then the "flipped," or secondary, side is sampled. If the value is 0, the nonflipped, or primary, side is sampled. The nonflipped side is the side that is visible when the Double Sided attribute of the surface is unchecked.

Returning to the network, the outColor of a checker texture node is connected to the colorIfTrue of the condition node. The outColor of a file texture node is connected to the colorIfFalse attribute of the same condition node. A bitmap image of a hundred dollar bill is loaded into the file texture node. The condition's Second Term is set to 1 and Operation is set to Equal. Last, the outColor of the condition node is connected to the color of a blinn material node. Thus, the flipped side of a primitive plane receives the Checker texture while the nonflipped side receives the File texture.

Figure 8.14 A single surface receives two textures with the help of a Condition utility. This scene is included on the CD as condition_f1ipped.ma.

oo a

0 0

Post a comment

  • Receive news updates via email from this site