Category: rendering

Animating with audio

using Maya setRange to control incandescence

setRange is a utility node that allows you to take values in one range, and map them into another range. Here is an example of setRange being used to remap the value of the translateY attribute to new values that control the incandescence of a shader.

This MEL script will create and attach a shader to selected objects, which links the translateY value of a Maya object to the incandescence of the shader.

The setRange utility is placed in between to control the output value range going into the shader. In this case, if the object’s translateY value is 10 the output will be 2, 1.25, 2, which produces a bright magenta color, if used as RGB values.

Using Maya hsvToRgb to cycle through the color spectrum

HSV to RGB is a utility node that allows you to convert an HSV (Hue-Saturation-Value) color into an RGB (Red-Green-Blue) color.

.inHsvR ranges from 0 to 360, representing degrees of a circle. We can use this to animate a shader to run through all the rainbow colors.

This MEL script will create and assign this shader network to selected objects.

Create Maya shaders that react to key frames

This MEL script was written specifically to automatically generate shaders for the equalizer in the animation below.

The script is set up to generate and assign shaders and attach the .translateY attribute of selected objects to the incandescence of the newly generated shader. Also creates a network that cycles the colors a bit at the same time.

Here is a snapshot of the network:

Get the script.

Maya Render Settings, File Name Prefix

Adding a path to the File Name Prefix dialog in the Render Settings will force Maya to write the sub directories specified:

You can write, for instance: subdir/renderPass1/myRen.

This will write files called myRen.####.ext into the directory path images/subdir/renderPass1/, as long as you are set up to render into the images directory.

You can use % to indicate variable values:

%s: scene name
%c: camera
%l: render layer

Example: %s/%c/%l/%s_%l

Maya fresnel texture connections MEL script

Connect this network to the reflectivity attribute of a shader to get the fresnel effect, ie reflections that increase in intensity as the rendered surface turns away from the camera.

Use this script to generate the fresnel network. Connect the ramp’s outAlpha to the Reflectivity attribute of your material.

[text]
string $myRamp = `shadingNode -asTexture ramp`;
string $myNode = `shadingNode -asUtility place2dTexture`;
connectAttr ($myNode + ".outUV") ($myRamp + ".uv");
connectAttr ($myNode + ".outUvFilterSize") ($myRamp + ".uvFilterSize");
removeMultiInstance -break true ( $myRamp + ".colorEntryList[1]");
setAttr ($myRamp + ".colorEntryList[0].color") -type double3 .5 .5 .5 ;
setAttr ($myRamp + ".colorEntryList[0].position") 0;
setAttr ($myRamp + ".colorEntryList[2].color") -type double3 0.1 0.1 0.1 ;
setAttr ($myRamp + ".colorEntryList[2].position") 1;
setAttr ($myRamp + ".interpolation") 4;
string $mySamplerInfo = `shadingNode -asUtility samplerInfo`;
connectAttr -f ($mySamplerInfo + ".facingRatio") ($myRamp + ".uCoord");
connectAttr -f ($mySamplerInfo + ".facingRatio") ($myRamp + ".vCoord");
[/text]

Select a material that has a “Reflectivity” attribute then run this script. The proper connections will be made automatically.

[text]
string $selShader[] = `ls -sl`;
string $myRamp = `shadingNode -asTexture ramp`;
string $myNode = `shadingNode -asUtility place2dTexture`;
connectAttr ($myNode + ".outUV") ($myRamp + ".uv");
connectAttr ($myNode + ".outUvFilterSize") ($myRamp + ".uvFilterSize");
removeMultiInstance -break true ( $myRamp + ".colorEntryList[1]");
setAttr ($myRamp + ".colorEntryList[0].color") -type double3 .5 .5 .5 ;
setAttr ($myRamp + ".colorEntryList[0].position") 0;
setAttr ($myRamp + ".colorEntryList[2].color") -type double3 0.1 0.1 0.1 ;
setAttr ($myRamp + ".colorEntryList[2].position") 1;
setAttr ($myRamp + ".interpolation") 4;
string $mySamplerInfo = `shadingNode -asUtility samplerInfo`;
connectAttr -f ($mySamplerInfo + ".facingRatio") ($myRamp + ".uCoord");
connectAttr -f ($mySamplerInfo + ".facingRatio") ($myRamp + ".vCoord");

connectAttr ($myRamp + ".outAlpha") ($selShader[0] + ".reflectivity");
[/text]