RenderMan Shader Functions


Latest update: April 1, 2006
ReturnsFunctionWhat
float.Dot product
float^Cross product
float,color,point,vector+ - * /Component-wise arithmetic
floatsin( r ) sine of an anagle in radians
floatasin( s ) radian arc whose sine is s
floatcos( r ) cosine of an angle in radians
floatacos( c ) radian arc whose cosine is c
floattan( r ) tangent of an angle in radians
floatatan( t ) radian arc whose tangent is t
floatatan( y, x ) radian arc whose tangent is y/x
floatPI 3.14159265...
floatradians( d ) Convert degrees to radians
floatdegrees( r ) Convert radians to desgrees
floatsqrt( v ) Square root
floatpow( x, y ) x y
floatexp( v ) e v
floatlog( v ) log ev
floatmod( v, b ) modulo( v, b )
floatabs( v ) Absolute value
floatsign( v ) -1. or 1. depending on the sign of v
floatmin( a, b ) Minimum
floatmax( a, b ) Maximum
floatclamp( v, min, max ) Clamps to range [min,max]
floatceil( v ) Smallest integer >= v
floatfloor( v ) Largest integer <= v
floatround( v ) Closest integer to v
floatstep( m, v ) 0. if v < m, 1. if v >= m
floatsmoothstep(min, max, val ) 0. if v < min, 1. if v > max, else smooth interpolation from 0. to 1.
colormix( c0, c1, t ) (1.-t)*c0 + t*c1
---printf( "string", v1, v2, ... ) Print to the console window
floatnoise(p) Perlin noise of a float or point
floatxcomp(p) X component of a point
floatycomp(p) Y component of a point
floatzcomp(p) Z component of a point
---setxcomp(p,v) Set the X component of a point to v
---setycomp(p,v) Set the Y component of a point to v
---setzcomp(p,v) Set the Z component of a point to v
float,colortexture( "name", s, t ) Return a color or a float from a texture
floatlength(V) Euclidean length of vector V
floatdistance( P1, P2 ) Distance between 2 points
floatarea(P) Returns the area covered by P, in pixels
floatdepth(P) Returns normalized depth of P (near=0., far=1.)
vectorcalculatenormal(P) Returns the new surface normal at P
vectornormalize(V) Returns unitized V
vectorfaceforward(V,I) Return V flipped to point opposite I
floatambient() Returns the sum of all ambient contributions
floatdiffuse(N) Returns sum of all diffuse contributions to normal N
floatspecular( N, eye, roughness ) Returns sum of all specular components to normal N and eye position eye
vectorreflect( I, N ) Returns the reflection vector of I around N
vectorrefract( I, N, eta ) Returns the refraction vector of I through N with index of refraction eta

Converting Points to Different Coordinate Spaces:

There are two ways to think of a "coordinate system": (1) an origin location and an orientation, and (2) a transformation. Keep both of these in mind when thinking about the meaning of RenderMan coordinate spaces.

point newpt = point "spacename" oldpt;
point newpt = point "spacename" ( oldx, oldy, oldz );

where the possible spacenames are:

"object"The coordinates in which an object is defines (=MC)
"world"The coordinates into which an object's points are transformed
"current"Default coordinate system (camera? world?)
"camera"The coordinate system with the eye at the origin looking in (LHS) +Z (=EC)
"shader"The world coordinate system that was active when a Surface shader was invoked

The same global transformation is used for both the world transformation and the eye transformation. Transformations that happen before the WorldBegin are assumed to be eye transformations. Transformations that happen after the WorldBegin are assumed to be object transformations.

How to Compute Lighting:

vector Nf = faceforward( normalize(N) ,I );
vector V  = normalize( -I );
Oi = Os;
Ci = Os * ( Cs * ( Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * Ks * specular( Nf, V, roughness ) );