the xformMatrix of the pCube1 transform node is connected to the matrix of a vectorProduct node.. normal-the output of the vectorProduct node is connected directly to outColor of a surfa
Trang 1are 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
iden-tity 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,
Maya’s 4 × 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
result-ing vector to the color of a material
normalCamera input1
output outColor
xformMatrix
matrix
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
Trang 2the xformMatrix of the pCube1 transform node is connected to the matrix of
a vectorProduct node (pCube1 is the small gray cube in figure 8.12.) the Camera of a samplerinfo node is connected to the input1 of the vectorProduct node
normal-the vectorProduct operation value is set to Vector Matrix Product normal-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 pCube1 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 pCube1 is at its rest position, its xformMatrix is an identity matrix and has no effect on the normalCam-era value thus, the values 0, 0, 1 are passed to outColor of the surfaceshader node
when pCube1 is rotated, however, the normalCamera value is multiplied by the new
xformMatrix and hence the color of the shape is affected for instance, if pCube1
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.13
–5 7 5 1(0 7 5 RGB)
0 0 1 1
Xform MatrixNormal Camera vector Vector Matrix Product result
7 0 7 0
5 7 –.5 0 –.5 7 5 0
0 0 0 1
=
Figure 8.13 A matrix calculation based on pCube1’s rotation of –45, –45, 0
The matrix numbers have been rounded off for easier viewing
when representing the matrix calculation, as with figure 8.13, the extra number 1 at the right side of the normal Camera vector (and at the bottom-right corner of the Xform Matrix) is necessary for this type of math operation; however, these numbers do not change as the corresponding objects go through various transformations
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_
Trang 3the Condition utility functions like a programming If Else statement If Else
state-ments are supported by Maya expressions and are written like so:
if ($test < 10){
print “This Is True”;
} else { print “This Is False”;
}
if the $test variable is less than 10, Maya prints “this is true” on the
com-mand 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 True;
} else { Color If False;
}first term and second term attributes each accept a single input or value, while the Color if true and Color if false attributes accept vector values or inputs
the operation attribute has six options: equal, not equal, greater than, less than,
greater or equal, and less or equal
with the Condition utility, you can apply two different textures to a single face By default, all surfaces in Maya are double-sided but only carry a single UV tex-
sur-ture space Hence, a plane receives the same texsur-ture on the top and bottom You can
avoid this, however, with the shading network illustrated by figure 8.14
the flippednormal of a samplerinfo node is connected to firstterm of a tion node the flipped normal attribute indicates the side of the surface that is ren-
condi-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 nected to the coloriftrue of the condition node the outColor of a file texture node
con-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
con-dition 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
Trang 4colorIf False
outC olor
colorIfT rue
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_flipped.ma
Switching Outputs
switch utilities provide multiple outputs from a single node that is, they switch between different values in order to create different results among the geometry assigned to their shading network since the application of a switch utility is unique in Maya, a step-by-step guide for a triple switch utility follows:
Map button Choose a triple switch from the switch Utilities section in the Utilities tab of the Create render node window
surfaces button all the surfaces assigned to the material appear in the list
4. right-click the first surface name in the switch attributes list and choose Map from the shortcut menu the Create render node window opens Choose a texture the texture node appears in the Hypershade window the out Color attribute of the texture node (for example, stucco.outColor) appears in the intriple column of the switch attributes list repeat this process for each of the remaining surfaces in the switch attributes list
Trang 5input[1].i nTriple
Figure 8.15 Color is controlled by a Triple Switch utility A simplified version of this scene is included on the CD
as triple_switch.ma
although these steps apply the switch to a material, you can apply them to any node that said, triple switches are designed for vector values and are best suited for
any attribute that uses rgB colors or XYZ coordinates
single switches, on the other hand, are designed for scalar values and are best suited for such attributes as Diffuse, eccentricity, reflectivity, or Bump Value the
single switch utility automatically chooses the outalpha attribute when a texture is
chosen in this case, the outalpha of each texture connects to the input[n].insingle
of the singleshadingswitch node the n in input[n].insingle corresponds to the slot
number of the switch attributes list the first slot is 0, the second is 1, and so on
although geometry is also connected to the singleshadingswitch node, the connection
lines are initially hidden nevertheless, the instobjgroups[n] of each geometry shape
node must be connected to the input[n].inshape of the singleshadingswitch node in
Trang 6this situation, the n of the instobjgroups[n] attribute refers to the hierarchy position
of an instanced attribute (see Chapter 7 for information on attribute instancing.)
in most cases, n is 0 the instobjgroups[n] convention applies equally to Double,
triple, and Quad switch utilities in addition, all the switches possess variations of
the input[n].insingle input.
Double switches are designed for paired or double attributes this makes the utility well suited for controlling UVs for example, in figure 8.16 a Cloth texture receives standard UV coordinates from a default place2dtexture node the repeat
UV values, however, are supplied by a Double switch utility in this case, the repeatUV
attributes of three additional place2dtexture nodes are connected to the input[n].
inDouble attributes of the doubleshadingswitch node place2dtexture1 has a repeat
UV value of 5, 5 place2dtexture2 has a repeat UV value of 25, 25 place2dtexture3 has a repeat UV value of 50, 50 this shading network offers the ability to adjust UVs
on multiple objects without affecting the base texture or necessitating the duplication
of the entire shading network
Figure 8.16 Repeat UV is controlled by a Double Switch utility A simplified version of this scene is included on the CD
as double_switch.ma
Trang 7the Quad switch utility is suited for handling a vector attribute and a single
attribute simultaneously for example, in figure 8.17 the outtriple attribute of the
quadshadingswitch node is connected to the color of a blinn material node the
outsingle attribute of the quadshadingswitch node is connected the diffuse of the
same blinn to split the switch’s output in such a way, it is necessary to use the
Con-nection editor the color attributes of three additional blinn nodes are connected to
the input[n].intriple attributes of the quadshadingswitch node the diffuse attributes
of the blinn nodes are also connected to the input[n].insingle attributes of the
quad-shadingswitch node each of the three blinn nodes has the outColor of a different
tex-ture connected to their color and diffuse attributes in this case, the diffuse attributes
do not need to correspond with the color attributes for instance, blinn2’s color can
be connected to input[0].intriple and blinn2’s diffuse can be connected to input[4]
insingle this ability to mix and match outputs and inputs allows for a great diversity of
results Hence, the Quad switch provides the flexibility necessary to texture crowds,
flocks, and swarms although such custom connections will function properly, they do
not appear in the switch attributes list of the switch’s attribute editor tab
Figure 8.17 Three different Blinn materials are dispersed among nine spheres using a Quad Switch utility
This scene is included on the CD as quad_switch.ma
Using Esoteric Utilities and Scene Nodes
several utilities and nodes fail to fit into a specific category of these, the stencil utility
provides an alternative method of blending maps together You can repurpose optical
fX and Unit Conversion utilities to fit a custom network although scene nodes (those
automatically generated by Maya) are not particularly flexible, they provide critical
services in a 3D scene
Trang 8sec-ture is chosen with as stencil selected, the new texsec-ture automatically receives a stencil
utility and two place2dtexture nodes the stencil utility stencils the new texture on top of the material color for example, in figure 8.18 a red logo is applied to a wall map with this technique although the stencil utility produces results similar to the Blend Colors utility (see Chapter 6), its methodology is fairly different
outUvFilterSize uvFilterSize
uvCoord
outUV
outUvFilterSiz
e uvFilterSize
outUV
uvC oor d
outAlpha mask
outC olor defaultC olor
outC olor image
Figure 8.18 A logo is applied to a wall with a Stencil utility This scene is included as on the CD as stencil.ma
in the example shading network, a red logo bitmap is loaded into a file ture named fileColor the outColor of fileColor is connected to image of a stencil node standard UV connections run from the first place2dtexture node to fileColor
tex-the second place2dtexture node is connected to tex-the stencil node with similar (albeit fewer) standard UV connections the outUV of the stencil’s place2dtexture node is connected to the uvCoord of fileColor’s place2dtexture node the outUvfiltersize of the stencil’s place2dtexture node is also connected to the uvfiltersize of fileColor’s place2dtexture node
normally, this minimal set of connections will cause the fileColor texture to completely overtake the blinn’s color to avoid this, the outalpha of a second file
Trang 9texture node, named fileMask, is connected to the mask of the stencil node the Mask
attribute controls where the new texture will show over the material color in this case,
a black and white bitmap is loaded into the fileMask node where the bitmap is white,
the material color shows through; where the bitmap is black, the red logo is rendered
at this point, the material color that is revealed by the Mask attribute can be
only the solid color of the material’s Color attribute to avoid this, the outColor of a
third file texture node, named filewall, is connected to the defaultColor of the stencil
node in this example, a bitmap photo of a wall is loaded into the filewall node if
file-wall was connected directly to the Color attribute of the blinn, it would not be visible
Applying Optical FX
the optical fX utility (found in the glow section of the Create Maya nodes menu in
the Hypershade window) is automatically created whenever light glow is applied to a
directional, area, or spot light the utility controls the look of the glow, halo, or lens
flare (for a discussion on this and other fog effects, see Chapter 2.)
oddly enough, the optical fX utility can be “grafted” onto a surface for example, in figure 8.19 the worldMatrix[0] attribute of a polygon lightbulb shape
node is connected to the lightworldMat of an opticalfX node this connection
ensures that the optical effect will occur in the center of the lightbulb regardless of
the lightbulb’s position the color of the blinn node is connected to lightColor of the
opticalfX node the blinn Color attribute is set to gold, which is picked up by the
opticalfX glow (the lightbulb surface is also assigned to the blinn.) last, the ignore
light attribute of the opticalfX node is checked; this informs the program that no
light is present the result is a glow that follows the lightbulb wherever it goes
Unfor-tunately, since the opticalfX node creates a post-process effect, the size of the glow
will not change You can animate the glow spread and Halo spread attributes of the
opticalfX node, however, if necessary
of this scene is included on the CD
as optical_bulb.ma A QuickTime movie is included asoptical_bulb.mov
Trang 10window > Hypergraph: Connections
menu (so that the option is checked) a unit conversion node should appear between the sphere and cone transform nodes
3. if the node fails to appear, choose show > auxiliary nodes from the graph Connections menu in the auxiliary nodes window, highlight the word
Hyper-unitConversion in the node types that are Hidden in editors field and click
the remove from list button
Hypershade work area, clicking the input and output Connections button reveals the unit conversion node
By default, Maya calculates the translation of objects using linear working units at the same time, Maya calculates the rotation of objects using angular work-ing units whenever two dissimilar working units, such as linear and angular, are used in the same network, Maya must employ a Unit Conversion node to create accu-rate calculations in the example illustrated in figure 8.20, a Unit Conversion node
is automatically provided with a Conversion factor attribute set to 0.017 You can change Conversion factor to achieve an exaggerated effect if the Conversion factor attribute is changed to 1, for example, the sphere will spin at a much greater speed when the cone is transformed
Trang 11Note: In general, it’s best to work in inches or centimeters On occasion, calculation errors occur if
a scene is set to meter, foot, or yard Linear units For example, a scene set to foot units can exceed the maximum unit limit of a camera clipping plane and objects will fail to fully draw in the camera view
Understanding Scene Nodes
render Partition, Default light set, and light linker nodes sit the farthest
down-stream in any shading network (see figure 8.21) the render Partition utility defines
which shading group nodes are called upon during a render
Light Linker
Default Render Utility List
Default Light Set
Render Partition
Figure 8.21 Scene nodes in a network
the Default light set utility carries a list of lights that illuminate all objects within a scene the instobjgroups[0] attribute of each light’s transform shape node
is connected automatically to the dagsetMembers[0] attribute of the defaultlightset
node if you uncheck the illuminates By Default attribute in a light’s attribute editor
tab, the connection is removed until the attribute is once again checked
the message of the defaultlightset node is connected automatically to link[n].
light and shadowlink[n].shadowlight of the lightlinker utility node the light linker
utility defines the relationship between lights and objects if a light is connected through
to defaultlightset node to the link[n].light attribute, the light illuminates all shading
groups connected to the lightlinker node if a light is connected through the
default-lightset node to the shadowlink[n].shadowlight attribute, then the light creates
shadows for all shading groups connected to the lightlinker node all shading group
nodes are connected automatically to the lightlinker node However, if you
Trang 12is made between the message attribute of the surface shape node to the ignore[n].
objectignored of the lightlinker node a connection is also made between the message
of the light shape node and ignore[n].lightignored of the lightlinker node if the
Make light links tool is applied, the connections are removed similar connections are made between the surface and light shape nodes’ message and the lightlinker node when the Break shadow links tool is applied
if a light is linked or unlinked in the relationship editor, the connections are identical to those made with the Make light links and Break light links tools for more information on the relationship editor, Make light links, and Break light links, see Chapter 2
the Default render Utility list node holds a list of all render utilities in Maya
although it cannot be used for any other purpose, it will show up in custom shading networks connected to each and every utility node
Chapter Tutorial: Creating Eye Glow with Advanced Math Utilities
in this section, you will re-create the tapetum lucidum of an eyeball the tapetum lucidum is a highly reflective membrane behind or within the cornea of many mam-mals and is responsible for the creepy eye glow seen at night (although a similar effect occurs when a flash photograph creates “red eye,” humans don’t possess the membrane.) You will use light info, Vector Product, and Multiply Divide utilities, as well as a ramp texture the tapetum lucidum of the eyeball geometry will become bright red only when both the camera and the scene’s spot light are pointing directly toward it (see figure 8.22)
an eyeball model a nUrBs disc, which sits behind the iris, is named tapetum and will provide the tapetum lucidum effect a spot light, named flashlight, is placed near the eye it will serve as the scene’s single light source and will figure into the calculations
the first lightInfoA and the second lightInfoB switch over to the lights tab
of the Hypershade window and MMB-drag the flashlightshape node into the work area
the flashlight transform node, and the tapetum geometry transform node into the Hypershade work area Connect worldMatrix[0] of the camera transform node to the worldMatrix of lightinfoa Connect the worldMatrix[0] of the tapetum geometry transform node to worldMatrix of lightinfoB
Trang 13Figure 8.22 The tapetum lucidum of an eye is re-created with the Light Info, Vector Product, and Multiply Divide utilities A
QuickTime movie is included on the CD as tapetum.mov
vec-torProductA, the second vectorProductB, the third vectorProductC, the fourth vectorProductD, and the fifth vectorProductE see figure 8.23 for the place-
ment of the nodes
lightInfoA persp
multiplyDivide lightInfoB
Figure 8.23 The custom shading network for the tapetum effect
Trang 145. Connect lightDirection of the flashlightshape node to input1 of vectorProducte
(the light Direction attribute is listed within the light Data section of the light shape node’s attribute list when the node is loaded into the Connection editor.) Connect xformMatrix of the flashlight transform node to matrix of vector-
Producte set vectorProducte’s operation to Vector Matrix Product and check
normalize output this will convert the lightDirection vector into a usable world space vector
vectorPro-ductC Connect lightDirection of lightinfoB to input1 of vectorProvectorPro-ductC set vectorProductC’s operation to Vector Matrix Product and check normalize output this will convert the direction of the tapetum geometry into a usable world space vector
vectorProducta Connect lightDirection of lightinfoa to input1 of Producta set vectorProducta’s operation to Vector Matrix Product and check
vector-on the normalize output buttvector-on this will cvector-onvert the camera directivector-on into a usable world space vector
output of vectorProducta to input1 of vectorProductB set vectorProductB’s operation to Dot Product and check normalize output this will calculate the angle between the tapetum geometry direction and the persp camera direction
output of vectorProducte to input1 of vectorProductD set vectorProductD’s operation to Dot Product and check normalize output this will calculate the angle between the tapetum geometry direction and the flashlight light direction
clampB Connect outputX of vectorProductB to inputr of clampa Connect outputX of vectorProductD to inputr of clampB for each clamp node, set
Minr to 0 and Maxr to 1 this will prevent any negative numbers from
reach-ing the end of the shadreach-ing network
clampa to input1X of the multiplyDivide node Connect outputr of clampB to input2X of the multiplyDivide node
12. set the multiplyDivide operation to Multiply if the flashlight points toward the eye, input2X becomes roughly 1 if the eye is “looking” at the camera, input1X also becomes 1 in this the case, the surface normals of the tapetum are pointing down the negative Z axis, whereby they are actually pointing in the same direction as the camera (you can see this if the Double sided attribute
is unchecked for the surface) if the eye is “looking” away, input1X becomes roughly 0 similarly, if the light points 90 degrees away from the eye, input2X becomes 0 Hence, when the eye points toward the camera and the light points toward the eye, the multiplyDivide node outputs a large value if either the
Trang 15camera or the light points away from the eye, the output value becomes smaller
only the angles of the light, camera, and geometry are compared although object position is part of the Xform Matrix attribute, the position of the object does not affect the output of the Dot Product operation in other words, the light might produce a normalized cosine of 0.5 whether it’s positioned at 0, 0, 0
or 500, 500, 500
the outputX of the multiplyDivide node to vCoord of the ramp node Create two handles in the ramp color field, one red and one black Place the black handle at a selected Position value of 0.75 and the red handle at a selected Position value of 1 the ramp should have a thin red strip at the top with the bulk of the color black set the ramp’s interpolation attribute to smooth
Connect outColor of the ramp node to incandescence of the blinn node assign the blinn to the tapetum geometry
the vector calculations will only be accurate if the tapetum geometry is at the top of the eye hierarchy
where the camera is, if the eye points toward it and the light points toward the eye, the tapetum lucidum will become bright red if you get stuck, the finished scene is saved as tapetum_finished.ma in the Chapter 8 scene folder