The Basics
Predefined Variables
Writing Numerical Expressions
Writing String Substitutions
Factory Functions
and Procedures
Accessing Client State
Waveform Generators,
Interpolators
Color and Point Functions
Math and Utility Functions
Operators
File Referencing
Examples
Slim utilizes the simple and powerful syntax of the TCL (see also http://tcl.sourceforge.net/) expr and subst commands to support parameter expressions. String parameters automatically undergo TCL string substitution while other parameters are evaluated as expressions only when their value providers are set to Expression.
By default, expressions are evaluated in the context of MTOR. This allows
expressions to access many predefined variables that may vary per frame,
per object, etc. You might instead want your expression to be evaluated
within Slim. This will allow you to access Slim's scripting environment.
Expressions evaluated within Slim will be evaluated once per job,
instead of once per frame. Use the Context
submenu
of the tcl menu to control your expression's evaluation context.
You can refer to predefined variables in your expressions or substitutions. We provide several useful variables describing the current project, object and temporal context. The simplest expression is simply a reference to a predefined variable, for example, $CONEANGLE.
You use numerical expressions (based on expr) to compute values for parameters of type: int, float, point, color, matrix, etc. Slim and *TOR automatically vectorize the computation for non scalar data types. If writing mathematical expressions isn't your bag, you can use very simple expressions to gain access to animation curves specified in your animation environment. For example, you can create a parameter curve in Maya and refer to that curve in place of an appearance parameter value. Another option is to rely upon the custom user interfaces that are provided to interactively edit TCL expressions. The rampEditor is one example of this.
You use string substitutions (based on subst) to construct strings to be passed to your shaders. Through standard TCL notation
[
command]
you can also make calls to TCL procedures like format and expr.You can extend the set of functions and variables available to your expressions by placing custom TCL procs in a file which is loaded via a LoadExtension directive in the appropriate initialization files.
Animation variables are setup automatically by Slim in conjunction with your animation system. The value of the variables depends on the rendering context. When rendering your scene, the variables take on values which you establish through RenderMan globals and the UI of your animation system. When rendering within Slim's Appearance Editor, values are preset as specified below.
pct
This variable contains a
number between 0 and 1 indicating the current frame's place in the
entire job. Pass this value to functions which vary over the duration of
your shot (see ease, easein, easeout and lerp).
f, F, F1, F2, F3, F4, F5
This variable contains the
current frame. When rendering within Slim, you can specify the value
for frame in the Appearance Editor window. To simplify the task of
constructing strings containing frame numbers we've also provided the
following variables: F, F1, F2, F3, F4, F5. The numeric
digit following the F represents the field width. This is
useful for constructing frame names whose alphabetical order matches
their numerical order. Here's an example string expression: images/test.$F4.tif.
On frame 10, for example, this expression would evaluate to: images/test.0010.tif.
f0
This variable contains the
the starting frame of your scene. When rendering within Slim, f0 is
determined by the sequence range preference.
fn
This variable contains the
the ending frame of your scene. When rendering within Slim, fn is
determined by the sequence range preference.
fps
This variable contains the
the frame rate as specified within RenderMan globals. When rendering
within Slim, fps is always 30. Fps is used automatically in the
computation of the time variable.
time (or t)
This variable contains the
current time in seconds. This value is computed automatically to be:
time = (frame-startframe) / fps.
pi
This is a constant containing
the value of PI - 3.14159265358979323846.
WSRoot, PROJ
This string variable contains
the pathname to your current workspace root location.
TMP
This string variable contains
the pathname to your current project temporary location.
OBJPATH
This string variable contains
the DAG pathname to your current object.
o,OBJNAME
This string variable contains
the tail or most specific portion of the hierarchical string contained
in OBJPATH.
NAMESPACE
This string variable contains
a string describing the namespace associated with the current
appearance. The namespace is usually the empty string ("").
When using file referencing features associated with your
modeling/animation system, this variable may contain a system-dependant
string which represents a scope for all external object references.
CHAN
This string variable contains
the channel index for non scalar data types. Remember that for these
data types, your expression is evaluated multiple (3) times.
JOBNAME
This string variable contains
the name of the job as specified in the "Display Name" field
of the RenderMan Globals.
ELEMENTNAME
This string variable contains
the name of the current subframe. For final frames, its the
Display Name, while for computed maps its the name of the camera object.
ELEMENTTYPE
This variable contains the
type of the current subframe. Possible values include:
final, reference, shadow, environment and reflection.
INSTANCEID
This string variable contains the appearance ID of the
current shader instance (equivalent to calling the result
of calling GetID on the appearance object).
INSTANCENAME
The name of the current
shader instance. This is the label field associated with every
appearance.
INSTANCETYPE
The type of the current
appearance. Possible values include: surface, displacement, ribbox,
ribgen, volume, light.
SEARCHPATHS
The current searchpaths in
standard TCL list notation. For more access to workspace settings,
you should use the workspace object.
LIGHTTYPE
The current lighttype. Only
valid when expanding light shaders. Possible values include: spot,
distant, environment. Currently only spot is implemented.
CONEANGLE
The cone angle, measured in
radians, of the client side spotlight associated with the currently
expanding lightsource.
PENUMBRAANGLE
The penumbra angle, measured
in radians, of the client side spotlight associated with the currently
expanding lightsource.
Here's a portion from our familiar appearance editor window. Recall that you must set the parameter's value provider to Expression in order to enable this expression entry.
The basic form of all expressions is quite simple. An expression is made of of a series of potentially nested function and/or procedure calls whose arguments are either return values of other functions or procedures or variable references. In TCL, a variable's value is accessed by preceding the variable name with the $ symbol. Slim, in conjunction with your animation software, conspire to set up a small set of special variables which you can refer to in your expressions. In this example, $pct is such a variable. Function calls can also be combined through the use of standard mathematics operators like +, *, /, %, etc.
It's important to distinguish between TCL procedures and TCL functions because they can only be used in certain contexts. A TCL function requires parentheses to enclose its comma separated argument list and is only meaningful within the scope of the expr command.. Above we see that lerp must be a function and thus we can infer that Slim requests TCL to evaluate the provided string as a TCL expression. In other words, Slim composes a TCL expression by prepending expr. To invoke a TCL procedure within the context of a TCL expression we are required to bound the procedure within square brackets as follows:
lerp(0,2,$pct) * [myproc 2 3 4]
Here myproc is a TCL procedure defined and loaded, presumably, via Slim's extension mechanisms.
Once you've developed an expression you can check it by invoking the Validate command in the menu associated with the tcl button to the left of your expression. There you'll also find controls to access special purpose interfaces which provide more convenient interfaces onto certain Slim functions or procedures.
Use string substitutions as string parameter values in your parameters. Note that this differs from numerical expressions above in that you enter the expression in-line in the standard text entry widget of the parameter (and not the expression entry). Typically, you'll use string substitutions to construct texture map references by embedding the frame number in your favorite representation. Here's a typical example:
$WSRoot/rmanpix/flapping.$F4.tif
In this example we refer to two predefined variables to construct a string that looks like:
/puddle/users/bones/maya/projects/default/pix/flapping.0033.tif
Note that this substitution is made at RIB generation time. The key point to understand is that the string that you enter will be passed to TCL's subst command. You can embed numerical expressions in substitutions through the use of the bracket ([]) operators. Here's an example that remaps the current frame into a different frame:
pix/flapping.[format %0.4d [expr fit($f,10,90,1,20)]].tif
This tricky example makes two nested function calls (first to expr, then to format) to create a string that is 4 digits, padded with zeros at the front. The fit function will remap the frame number ($f) into a different range. In this example frames between 10 and 90 will be mapped to between 1 and 20. Frames outside this range will be 1 or 20. The format cmd will then convert the results of the fit.
A simpler variation of the same command can be constructed with a single procedure call:
pix/flapping.[fit -pad 4 -in 10 90 -out 1 20].tif
Note that the fit functionality is provided in both functional and procedural forms.
You can use standard functions and procedures in your expressions.
As discussed above, functions and procedures have different syntax and
can be used in difference contexts. Here, procedure calls are denoted
using the notation:
[procname arg1 arg2 ..].
[clientcmd "cmd"] (aliases: mel)
The clientcmd procedure causes an arbitrary expression to be evaluated
in the client (e.g. MTOR) application environment. Here're some examples:
[clientcmd "getAttr $OBJPATH.mystring"]
This command executes the mel getAttr command and replaces the $OBJPATH variable with the name of the object that the associated appearance is attached to. Presumably a user has created the variable mystring and placed interesting information therein.
[mel "getAttr -size curve1.controlPoints"]
We've aliased hostcmd under the name mel for brevity and clarity for
Maya users. Note that the command takes a single string argument representing
the host command and it's arguments. Variable substitution is performed
by *TOR and so special symbols may require escaping via the backslash
symbol. Note, too, that this command can also be utilized in
standard parameter animation expressions as long as the result can be evaluated
numerically.
[clientattr "attr" t] (aliases: mattr)
[coordsys shapename]
Corrects the name of a coordinate system reference for file referencing name munging.
[mattr "attr" t] (aliases: mayaattribute)
This procedure accesses the attribute named by "attr" in your Maya scene. The format for the attribute specification is the standard Maya syntax.
[st0 "objectname"], [st1 "objectname"] (aliases: STMatrix0, STMatrix1)
Use these procedures to gain access to object specific texture mapping coordinates or transformations from your modeler. In this manner you connect the texture transformations on any object in your scene to a particular appearance parameter. The Mondo.sl, file provides an example of how to use this information in your own shaders. The objectname parameter is the name of a "place2dTexture" Maya object. It does not need to be the same object to which you are attaching the RenderMan shader.
[shdmap cameraname (px,py,pz,nx,ny,nz)]
Returns the name of the map associated with the shadow pass driven by the lightsource named cameraname. If you're using pointlight shadows, the optional second argument should be used to choose the axis.
[refmap cameraname]
Returns the name of the map associated with the reflection pass driven by the camera named cameraname. In the case of reflections maps, cameraname is often the name of the reflecting plane geometry.
[envmap cameraname]
Returns the name of the map associated with the environment pass driven by the camera named cameraname.
[imgmap cameraname]
Returns the name of the map associated with the reference pass driven by the camera named cameraname.
[zmap cameraname]
Returns the name of the map associated with the depth pass driven by the camera named cameraname.
[txmake args]
Returns the name of the map resulting for the conversion of a source texture file into Pixar texture file format. Here are the optional arguments:
lerp(a,b,t)
Linearly interpolate between a and b using t, t in the range 0 to 1.flerp(a,b,f,startf,endf)
Same as lerp but more convenient for frame ranges. A value between a and b is returned when f is between startf and endf.ease(a,b,t)
Cubic interpolation between a and b using t, t in the range 0 to 1. Tangent of zero at both ends.fease(a,b,f,startf,endf)
Same as ease but more convenient for frame ranges. A value between a and b is returned when f is between startf and endf.easein(a,b,t)
Quadratic interpolation between a and b using t, t in the range 0 to 1. Tangent of zero at beginning.feasein(a,b,f,startf,endf)
Same as easein but more convenient for frame ranges. A value between a and b is returned when f is between startf and endf.easeout(a,b,t)
Quadratic interpolation between a and b using t, t in the range 0 to 1. Tangent of zero at end.feasout(a,b,f,startf,endf)
Same as easeout but more convenient for frame ranges. A value between a and b is returned when f is between startf and endf.noise(t)
Perlin style noise, returns values between -1 and 1. t is the wave parameter representing pseudo periods of the noise function. If you want 5 periods of noise over your animation you can use: noise(5 * $pct)fit(x,a1,b1,a2,b2) (also map)
Takes a value x between a1 and b1 and remaps it into the range described by a2 and b2. The remapping is a linear function and values of x which lie outside the range (a1,b1) are clamped.The following wave generation functions are presented in Waveform Generators for Computer Graphics by C. Schlick - Graphic Gems Vol V. The parameter t is as above, s is the shape factor in the range [-1,1], f is the frequency variance in the range [0,1] and a is the amplitude variance in the range [0,1].
rwave(t,s,f,a) Generates rectangular-like waves.
twave(t,s,f,a) Generates triangular-like waves.
swave(t,s,f,a) Generates sinusoidal-like waves.
[spline1 $pct {k1 v1} {k2 v2} {k3 v3}...]
Returns the evaluation of the 1-D spline given by the list of knots provided as arguments. Knots are x-y pairs where the x values are monotonically increasing parameter values and y is the function's value. The spline is deemed 1D because there's a single y value for each x.[spline3 $pct {k1 {r1 g1 b1}} {k2 {r2 g2 b2}}...]
Returns the evaluation of the 3-D spline given by the list of knots provided as arguments. Knots are x-y pairs where the x values are monotonically increasing parameter values and y is the function's value. The spline is deemed 3D because there're three y values for each x.[fit args] (-pad %d, -in a b, -out c d)
A procedure version of the function described above.
rgb(r,g,b), rgbi(ir,ig,ib)
Allow the specification of color (vector) parameters. r,g,b in the range [0,1], ir,ig,ib in the range [0,255].hsv(h,s,v), hsvi(ih,is,iv)
Allow the specification of color (vector) parameters in the HSV color space. h,s,v in the range [0,1], ih,is,iv in the range [0,255]. Note that this will immediately convert the hsv values to rgb values.xyz(x,y,z)
Allow the specification of point (vector) parameters.
rad(d) Convert degrees to radians.
deg(r) Convert radians to degrees.
abs(x) Absolute value of x.
acos(x) Arc cosine of x, in the range 0 to pi.
asin(x) Arc sine of x, in the range -pi/2 to pi/2.
atan(x) Arc tangent of x, in the range -pi/2 to pi/2.
atan2(x,y) Arc tangent of x/y, in the range -pi/2 to pi/2.
ceil(x) Smallest integer not less than x.
cos(x) Cosine of x (x in radians).
cosh(x) Hyperbolic cosine of x.
double(i) Real value equal to integer i.
exp(x) e raised to the power x.
floor(x) Largest integer not greater than x.
fmod(x,y) Real remainder of x divided by y.
hypot(x,y) Square root of (x*x + y*y).
int(x) Integer value produced by truncating x toward 0.
log(x) Natural logarithm of x.
log10(x) Base 10 logarithm of x.
pow(x,y) x raised to the power y.
rand(), srand(x) return random values between 0 and 1. srand determines its value based on the provided integral seed.
round(x) Integer value produced by rounding x.
sin(x) Sine of x (x in radians).
sinh(x) Hyperbolic sine of x.
sqrt(x) Square root of x.
tan(x) Tangent of x (x in radians).
-a Negative of a.
!a Logical NOT: 1 if a is zero, 0 otherwise.
~a Bit wise complement of a.
a * b Multiply a by b.
a / b Divide a by b.
a % b Remainder after dividing a by b.
a + b Add a and b.
a - b Subtract b from a.
a < b 1 if a is less than b, 0 otherwise.
a > b 1 if a is greater than b, 0 otherwise.
a <= b 1 if a is less than or equal to b, 0 otherwise.
a >= b 1 if a is greater than b, 0 otherwise.
a == b 1 if a is equal to b, 0 otherwise.
a != b 1 if a is not equal to b, 0 otherwise.
a ? b : c Choice: if a is non zero then b, else c.
Maya supports powerful file referencing functionality which relies on name munging to prevent name collisions between objects in separate files. When refering to object names in the client, Slim and MTOR have special features to accomodate this.
When a palette is loaded, all appearances are tagged with a namespace name that is derived from the name of the referenced file they're stored in. This was broken in Slim 1.0 and so the namespace was always the empty string. As of Maya 2.5 there's no fool-proof way to determine the true namespace value so MTOR must currently rely on the filename to make an educated guess at the name. Until we get more support from Alias in the Maya API, customers should not use the -namespace option of the the mel "file" command to override the default naming during file referencing operations. This becomes an issue primarily when referencing a single file multiple times.
In our current implementation, the names in expressions are not expected to update, rather all this magic stuff happens in the evaluation of particular procs and depends upon an appearance's namespace.
MTOR implements a few special scripting commands that allow you to refer to Maya objects. These include: mattr, clientcmd (mel), coordsys, stmatrix, shdmap, .... MTOR automatically attempts to correct for file referencing name munging. This means that users shouldn't normally need to worry about constructing special expressions with the NAMESPACE variable.
EXCEPT: there is some special-case code in the name munging code to support the use of file references in the "reference the same file many times" case. No name munging is performed if incoming name contains one of the special separator characters: ':' or '_' AND an object with that name is present in the scene. This logic is sufficient for allowing a customer to perform site-specific name munging through their own custom TCL procs. In this case a mattr call might look like:
[mattr [sitePrefixGenerator]sphere.translateX]]
assuming that "proc sitePrefixGenerator {}" has been loaded into both
MTOR and Slim via an instance of TOR.ini as described in the
standard RAT initialization documentation.
For non programmers, the simplest method for parameter animation leverages the power of the animation system rather than the expression syntax. If you are an Alias user, the simplest expressions will be references to your Alias animation channels. Here are some examples:
[mattr "Ball.translate" $f] This example names a collection of channels (translateX, translateY, translateZ) and will return a vector value. You'd probably use and expression like this to compute a point or vector parameter for your shader.
For programmers, it's often simpler to throw together a simple expression than it is to construct a channel, build the animation, then refer to that in an expression. Here are some simple expressions:
lerp(10,100, $pct) -linearly interpolate between 10 and 100 over the duration of the animation.
ease(-1, 1, $pct) -smoothly interpolate between -1 and 1 over the animation duration. Starts slow, speeds up, ends slow.
abs(ease(-1,1,$pct)) -make sure the previous is always positive.
noise($f/100) * sin(rad($f))) -shows math operators.
ease( rgb(1,0,0), rgb(0,1,0), $pct ) -shows color interpolation.
$frame < 10 ? rgb(1,0,0) : rgb(0,1,0) -shows choice operator.
fit($f, 10, 90, 1, 20) - useful for animated textures. This example lays the animated texture frames 1-20 onto output frames 10-90. For output frames less than 10, we'll use texture frame 1. For output frames greater than 90, we'll use texture frame 20.
Now that you've got the hang of it, you can get a little fancier.
[expr 5 * [mattr "sphere.translateX" $f]]
$f < 10 ? [mattr "s.translateX" $f] : 0
Pixar Animation Studios
|