The RenderMan Interface 3.1Section 11 - Types

The Shading Language is strongly typed and supports the following basic types:

Floats | Colors | Points | Strings | Uniform and Varying Variables


Floats

Floats are used for all scalar calculations. They are also used for integer calculations.

Floating-point variables are defined as follows:

     float a, b=1;

The initialization value may be any scalar expression that contains only uniform operands.

Colors

The Shading Language implements color as an abstract data type independent of the number of samples and the color space. The major operations involving color are color addition (`+' operator) corresponding to the mixing of two light sources, and color filtering (`*' operator) corresponding to the absorption of light by a material. In each case these color operations proceed on a component by component basis.

The number of color samples used in the rendering program is set through the RenderMan Interface. Once the number of color samples has been specified, colors with the appropriate number of samples must be passed to a shader. When setting the number of samples, the user can also specify a transformation from RGB space to this n sample color space. This allows a shader to convert color constants to the specified color space.

Color component values of 0 correspond to minimum intensity, while values of 1 correspond to maximum intensity. A color constant of 0 is equivalent to black, and of 1 is equivalent to white. However, values outside that range are allowed (values less than zero decrement intensity from other sources).

Color variables may be declared with:

      color c, d=1, e=color(1,0,0);

The initialization value may be any scalar or color expression that contains only uniform operands. If a scalar expression is used, its value is promoted to a color by duplicating its value into each component.

Color constants are specified by:

      color [space] (u,v,w)

The optional specifier space indicates the color coordinate system of the 3-tuple. The default color coordinate system is "rgb." Table 11.1, Color Coordinate Systems, lists the color coordinate systems that are supported in the Shading Language.

Table 11.1 Color Coordinate Systems

Coordinate System Description
"rgb" Red, green, and blue
"hsv" Hue, saturation, value
"hsl" Hue, saturation, lightness
"xyz", "XYZ"CIE XYZ coordinates
"xyY"CIE xy and Y
"YIQ"NTSC coordinates

Points

Point variables are (x,y,z) triples of floats that are used to store locations and direction vectors.

All calculations involving points are assumed to take place in an implementation-dependent coordinate system, usually either the camera or world coordinate system. A procedure exists to transform a point from the shading coordinate system to various named coordinate systems, or to define a point in one of several coordinate systems and transform it to the shading coordinate system. It should be noted that sometimes direction vectors do not transform in the same way as points, and therefore it is not always correct to transform direction vectors.

A number of standard coordinate systems are known to a shader. These include: "raster," "screen," "camera," "world," and "object." These are discussed in the section on Camera in Part I. In addition, a shader knows the coordinate systems shown in Table 11.2, Point Coordinate Systems.

Table 11.2 Point Coordinate Systems

Coordinate System Description
"shader" The coordinate system in which the shader was defined. This is the "object" coordinate system when the shader is defined.
"current"The coordinate system in which the shading calculations are being performed. This is normally the "camera" or "world" coordinate system.
"string"A named coordinate system established using RiCoordinateSystem.

Point variables are declared:

     point u, v=1, w=point(1,1,1);

The initialization value may be any scalar or point expression that contains only uniform operands. If a scalar expression is used, the value is promoted to a point by duplicating its value into each component.

Point constants default to be in the "current" coordinate system. Point constants can be specified in any known coordinate system with:

     point [space] (x,y,z)

For example,

     point "world" (0,0,0)

defines a point at the position (0,0,0) in world coordinates. This point is implicitly transformed to the "current" coordinate system. Points passed through the RenderMan Interface are interpreted to be in "shader" or "object" space, depending on whether the point variable was set using a shader command or a geometric primitive command, respectively.

Strings

Strings are used to name external objects (texture maps, for example). The only allowed string expressions are constant strings and string equality tests.

Uniform and Varying Variables

Shaders contain two classes of variables: uniform variables are those whose values are constant over a surface, while varying variables are those whose values change over the surface. For example, shaders inherit a color and a transparency from the graphics state. These values do not change from point to point on the surface and are thus uniform variables. Color and opacity can also be specified at the vertices of geometric primitives (see Section 5, Geometric Primitives). In this case they are bilinearly interpolated across the surface, and therefore are varying variables.

Local variables and arguments to shaders are declared to be either uniform or varying by specifying a storage modifier:

     varying point p;
     uniform point q;

Variables declared in the argument list of a shader are assumed to be uniform variables by default. These are sometimes referred to as instance variables. If a variable is provided only when a shader is instanced, or if it is attached to the geometric primitive as a whole, it should be declared a uniform variable. However, if a variable is to be attached to the vertices of geometric primitive, it should be declared as a varying variable in the shader argument list.

Variables declared locally in the body of a shader, as arguments to a function, or as local variables are assumed to be varying. Declaring a variable to be uniform inside a shader or function definition is never necessary, but may allow the compiler to generate more efficient code.

If a uniform value (or a constant) is assigned to a varying variable or is used in a varying expression, it will be promoted to varying by duplication. It is an error to assign a varying value to a uniform variable or to use a varying value in a uniform expression.


RenderMan Interface Table of Contents

RenderMan Artist Tools | RenderMan Toolkit
Looks | Textures
Pixar Home Page

Copyright © 1998 Pixar. All rights reserved. RenderMan® is a registered trademark of Pixar.
Pixar Animation Studios, 1001 West Cutting Blvd., Richmond, CA 94804
(510) 236-4000 (voice) (510) 236-0388 (fax)