26.01.2015 Views

The RenderMan Interface - Paul Bourke

The RenderMan Interface - Paul Bourke

The RenderMan Interface - Paul Bourke

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A matrix can be declared:<br />

matrix zero = 0;<br />

matrix ident = 1;<br />

matrix m = matrix (m00, m01, m02, m03, m10, m11, m12, m13,<br />

m20, m21, m22, m23, m30, m31, m32, m33);<br />

Assigning a single floating-point number x to a matrix will result in a matrix with diagonal<br />

components all being x and other components being zero (i.e., x times the identity matrix).<br />

Constructing a matrix with 16 floats will create the matrix whose components are those<br />

floats, in row-major order.<br />

Similar to point-like types, a matrix may be constructed in reference to a named space:<br />

matrix q = matrix ”shader” 1;<br />

matrix m = matrix ”world” (m00, m01, m02, m03, m10, m11, m12, m13,<br />

m20, m21, m22, m23, m30, m31, m32, m33);<br />

<strong>The</strong> first form creates the matrix that transforms points from ”current” space to ”shader”<br />

space. Transforming points by this matrix is identical to calling transform(”shader”,...). <strong>The</strong><br />

second form prepends the current-to-world transformation matrix onto the 4 × 4 matrix<br />

with components m 0,0 ...m 3,3 . Note that although we have used ”shader” and ”world” space<br />

in our examples, any named space is acceptable.<br />

11.5 Strings<br />

Strings are used to name external objects (texture maps, for example). String literals (or<br />

constants) are enclosed in double quotes, as in the C language, and may contain any of the<br />

standard C “escape sequences” (such as \n for newline or \" for a quote).<br />

11.6 Arrays<br />

<strong>The</strong> Shading Language supports 1D arrays of all the basic data types. Local variable arrays<br />

must be of fixed, predeclared (compile-time) lengths, though arrays can be of indeterminate<br />

length for shader instance variable and function formal parameter declarations. Zero<br />

and negative-length arrays are not permitted.<br />

As in C, the syntax for declaring an array of any data type uses square brackets, as datatype[length].<br />

length is a float constant, which is rounded down to generate an integer length. <strong>The</strong> syntax<br />

for specifying the data of a constant array uses curly braces, as {value1, value2, ...}. For<br />

example:<br />

float a[10];<br />

uniform color C[4]; float b[4] = { 3.14, 2.17, 0, -1.0 };<br />

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!