Examples Of Utility Nodes

Hello all,

Often I have found lot of hassle can be saved by using utliity nodes instead of coding. But the documentation of utility nodes do not reveal their UTILITY to everyone. I have seen cool uses of ramp nodes, array mapper, etc, but they were not readily apparent from documentation.

So my intent for this thread is to ask people to contribute simple/cool/wicked examples of utility nodes which will illustrate their usefulness and power.

So when you get a 15 min break, come up with an example and post here.
The person who posts most examples gets the title of Utility CZAR.

--Amit

PS: Moderators, can we make this post sticky

ehmm.. thats news to me. Have an example yourself?

I definitely won't be winning any prizes here, but this is a great topic.
Here's a simple one:
The Reverse node has vector (3 values or channels) input and output. The output will return "1-input" for each channel.
This can be used in ik_fk switching. Say you have 3 joint chains: ik, fk, and binding. The binding chain is used to deform the mesh.
Each of the binding joints is orient constrained between its corresponding joint on the ik and fk chains.
A controller (null or any object) is created with an ik_fk attribute who's values range from 0 to 1 - this is the switch. A reverse node is created and the value of the ik_fk attribute is connected to one of the channels of the reverse node (say InputX), so now the corresponding output channel of the reverse node (say Output X) will have the value "1- ik_fk".
The input value of the reverse node is connected to one set of joint weights in each of the orient constraints (ie W0 or W1), and the output of the reverse node is set to the other set of joint weights (W0 or W1).
As the value of ik_fk is changed between 0 and 1, the influence weights of the ik and fk chains are adjusted accordingly - changing the weighted influence each has on the corresponding binding joint.
To track the value of the reverse.OutputX:
Add an attribute to the swtich object. Maybe name it Reverse Out X. Connect the OutputX of the reverse node to this channel.

CODE
//This creates three shaders namely
//lumi_shader, average_grey_shader, range_shader
//and hooks them to three planes
//Step1: Browse and hook a color image to file1 node
//Step2: Render to see results

//Warning Creating a new file
file -f -new;

// Create file texture with texture placement //
shadingNode -asTexture file;
shadingNode -asUtility place2dTexture;
connectAttr -f place2dTexture1.coverage file1.coverage;
connectAttr -f place2dTexture1.translateFrame file1.translateFrame;
connectAttr -f place2dTexture1.rotateFrame file1.rotateFrame;
connectAttr -f place2dTexture1.mirrorU file1.mirrorU;
connectAttr -f place2dTexture1.mirrorV file1.mirrorV;
connectAttr -f place2dTexture1.stagger file1.stagger;
connectAttr -f place2dTexture1.wrapU file1.wrapU;
connectAttr -f place2dTexture1.wrapV file1.wrapV;
connectAttr -f place2dTexture1.repeatUV file1.repeatUV;
connectAttr -f place2dTexture1.offset file1.offset;
connectAttr -f place2dTexture1.rotateUV file1.rotateUV;
connectAttr -f place2dTexture1.noiseUV file1.noiseUV;
connectAttr -f place2dTexture1.vertexUvOne file1.vertexUvOne;
connectAttr -f place2dTexture1.vertexUvTwo file1.vertexUvTwo;
connectAttr -f place2dTexture1.vertexUvThree file1.vertexUvThree;
connectAttr -f place2dTexture1.vertexCameraOne file1.vertexCameraOne;
connectAttr place2dTexture1.outUV file1.uv;
connectAttr place2dTexture1.outUvFilterSize file1.uvFilterSize;

///////////////////////////////////////////////////////////////
// Luminance Shader , rgb to luminance
// Luminance = 0.3 * red + 0.59 * green + 0.11 * blue
// (perceptually based weights)
///////////////////////////////////////////////////////////////

// Create Luminance node
shadingNode -asUtility luminance;
// Connect file1.outColor to luminance1.value. //
connectAttr -force file1.outColor luminance1.value;

//Now create lumi_shader
shadingNode -asShader lambert -n lumi_shader;
sets -renderable true -noSurfaceShader true -empty \
-name lumi_shaderSG;
connectAttr -f lumi_shader.outColor lumi_shaderSG.surfaceShader;

//Connect outValue of luminance1 to all color channels in lumi_shader
connectAttr -force luminance1.outValue lumi_shader.colorR;
connectAttr -force luminance1.outValue lumi_shader.colorG;
connectAttr -force luminance1.outValue lumi_shader.colorB;

///////////////////////////////////////////////////////////////
//Average Grey Shader, rgb averaged to create greyscale image
//We may want to average the colors instead of using luminance node
///////////////////////////////////////////////////////////////

//Create plusMinusAverage node
shadingNode -asUtility plusMinusAverage;

//Connect each of the outcolor (R,G,B) to 1d inputs
connectAttr -force file1.outColorR plusMinusAverage1.input1D[0];
connectAttr -force file1.outColorG plusMinusAverage1.input1D[1];
connectAttr -force file1.outColorB plusMinusAverage1.input1D[2];

//Set the operation to average
setAttr plusMinusAverage1.operation 3;

//Now create average_grey_shader
shadingNode -asShader lambert -n average_grey_shader;
sets -renderable true -noSurfaceShader true -empty \
-name average_grey_shaderSG;
connectAttr -f average_grey_shader.outColor \
average_grey_shaderSG.surfaceShader;

//Connect output1D to all color channels (R,G,B)
//of the average_grey_shader
connectAttr -force plusMinusAverage1.output1D \
average_grey_shader.colorR;
connectAttr -force plusMinusAverage1.output1D \
average_grey_shader.colorG;
connectAttr -force plusMinusAverage1.output1D \
average_grey_shader.colorB;

///////////////////////////////////////////////////////////////
// Range Shader, Change the range of colors to get new effect
// This will create the image with magenta push
///////////////////////////////////////////////////////////////

//Create setrange node
shadingNode -asUtility setRange;
//Connect outcolor of file to this node
connectAttr -force file1.outColor setRange1.value;
//Set range parameters
setAttr "setRange1.oldMaxX" 1;
setAttr "setRange1.oldMaxY" 1;
setAttr "setRange1.oldMaxZ" 1;
setAttr "setRange1.minX" 0.0;
setAttr "setRange1.minY" 0.25; //reduce green range
setAttr "setRange1.minZ" 0.0;
setAttr "setRange1.maxX" 1.0;
setAttr "setRange1.maxY" 0.5; //reduce green range
setAttr "setRange1.maxZ" 1.0;

//Create a range_shader
shadingNode -asShader lambert -n range_shader;
sets -renderable true -noSurfaceShader true -empty \
-name range_shaderSG;
connectAttr -f range_shader.outColor range_shaderSG.surfaceShader;

//Connect outvalue of setRange1 to color channel of shader
connectAttr -force setRange1.outValue range_shader.color;

///////////////////////////////////////////////////////////////
// Create three planes and hook the shaders,
///////////////////////////////////////////////////////////////

nurbsPlane -ch on -o on -po 0 -ax 0 1 0 -w 1 -lr 1 -n lumi_plane;
move -a -2 0 0;
sets -e -forceElement lumi_shaderSG;

nurbsPlane -ch on -o on -po 0 -ax 0 1 0 -w 1 -lr 1 -n average_plane;
move -a 0 0 0;
sets -e -forceElement average_grey_shaderSG;

nurbsPlane -ch on -o on -po 0 -ax 0 1 0 -w 1 -lr 1 -n range_plane;
move -a 2 0 0;
sets -e -forceElement range_shaderSG;

select -r file1;//Browse to hook a color image
//Render to see results

QUOTE(ewerybody @ 06/05/08, 01:44 AM) [snapback]286727[/snapback]
ehmm.. thats news to me. Have an example yourself?
PS: ewerybody there is no need to scoff at this idea: You have also proposed things like this. For example "1k Mel Competition, lets see what you can do"

Are we focusing on shading? I mean maya can use any node in utilitarian use. Tough only nodes marked shading export to mental ray. And for shading theres NO node like the shading switches to do magic shading networks.

Anyway the reason they arent documented is that theres quite literary a unlimited amount of suse for them.

Can one submit a new node?

QUOTE(Joojaa @ 06/06/08, 12:43 AM) [snapback]286780[/snapback]
Are we focusing on shading? I mean maya can use any node in utilitarian use.
Shading examples are fine as well. (If you are ok with shading stuff posted on mel forum instead of rendering forum, may be ths thread could be mirrored on both forums if we get a good mix of examples)

QUOTE
Anyway the reason they arent documented is that theres quite literary a unlimited amount of suse for them.
Joojaa I agree on this and my thinking was if we can conjure some example it would be nice to see how people assemble things together. So this is kind of show and tell. Moreover I have seen you using chaining these nodes in interesting and smart ways.

QUOTE
Can one submit a new node?
Absolutley

QUOTE(amitc @ 06/06/08, 03:52 PM) [snapback]286796[/snapback]
Shading examples are fine as well. (If you are ok with shading stuff posted on mel forum instead of rendering forum, may be ths thread could be mirrored on both forums if we get a good mix of examples)

No mirroring please, a web page once we have sufficient amount of examples.

Anyway for shading it certainly would make sense to make one exaple for each and every utility node. (and several for sampler info)

Ok heres my all time favorite (because its the first shader i ever did with maya shading networks), and in very basic form, texture. Please note the offset attribute in the ramp. I dint want to convolute it with the bump map trick, wich makes it even cooler.

CODE
file -f -new;
createNode surfaceShader -n "surfaceShader2";
createNode ramp -n "ramp2";
    addAttr -sn "offset" -ln "offset" -at "double";
    setAttr ".t" 1;
    setAttr -s 3 ".cel";
    setAttr ".cel[0].ep" 0.85000002384185791;
    setAttr ".cel[0].ec" -type "float3" 1 0 0;
    setAttr ".cel[1].ep" 0.86000001430511475;
    setAttr ".cel[1].ec" -type "float3" 0.5 0 0.5;
    setAttr ".cel[2].ep" 1;
    setAttr ".cel[2].ec" -type "float3" 0 0 1;
    setAttr -k on ".offset" 0.06;
createNode place2dTexture -n "place2dTexture5";
createNode clamp -n "clamp1";
    setAttr ".mx" -type "float3" 1 9.9999997e-005 0;
createNode plusMinusAverage -n "plusMinusAverage1";
    setAttr -s 2 ".i3";
    setAttr -s 2 ".i3";
createNode ramp -n "ramp1";
    setAttr -s 2 ".cel";
    setAttr ".cel[0].ep" 0;
    setAttr ".cel[2].ep" 1;
    setAttr ".cel[2].ec" -type "float3" 1 1 1;
createNode place2dTexture -n "place2dTexture3";
createNode noise -n "noise1";
    setAttr ".a" 0.46279999613761902;
    setAttr ".dm" 7;
    setAttr ".fr" 1.3200000524520874;
    setAttr ".nty" 0;
createNode place2dTexture -n "place2dTexture2";
    setAttr ".tf" -type "float2" -0.27000001 0;
    setAttr ".re" -type "float2" 1 0;
    setAttr ".r" 50.58;
connectAttr "ramp2.oc" "surfaceShader2.oc";
connectAttr "place2dTexture5.o" "ramp2.uv";
connectAttr "clamp1.opr" "ramp2.u";
connectAttr "clamp1.opr" "ramp2.v";
connectAttr "place2dTexture5.ofs" "ramp2.fs";
connectAttr "plusMinusAverage1.o3" "clamp1.ip";
connectAttr "ramp1.oc" "plusMinusAverage1.i3[0]";
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3x";
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3y";
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3z";
connectAttr "place2dTexture3.o" "ramp1.uv";
connectAttr "place2dTexture3.ofs" "ramp1.fs";
connectAttr "noise1.oc" "ramp1.cel[0].ec";
connectAttr "place2dTexture2.o" "noise1.uv";
connectAttr "place2dTexture2.ofs" "noise1.fs";

Its good for a number of stuff not readily apparent such as acorn textures etc...

It manily demostrates use of clamp, for the ramp input. And +- average for making it easier to animate.

Joojaa interesting example

QUOTE(Joojaa @ 06/07/08, 03:12 AM) [snapback]286821[/snapback]
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3x";
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3y";
connectAttr "ramp2.offset" "plusMinusAverage1.i3[1].i3z";
Looks like cyclic connection, so not sure how its executed, moreover if I delete this connection the result looks the same.

Can you explain what this connection does?

QUOTE(amitc @ 06/10/08, 09:36 PM) [snapback]286952[/snapback]
Looks like cyclic connection, so not sure how its executed, moreover if I delete this connection the result looks the same.
Can you explain what this connection does?

Its not cyclic it just resides in the node (no computation takes place, moreover cyclic inst forbidden in dg), because i tend to think the best feedbackis in the ramp. Try cahnging the value. It drives how far up or down the leak goes so if you animate it you will see the goo running down the surface as if.