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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

As in C, individual array elements may referenced using the familiar square bracket notation.<br />

An array element index is a float expression, which is rounded down to generate and<br />

integer index. Shading Language arrays perform over/underrun checking at run-time.<br />

Also as in C, arrays themselves are not atomic objects — in other words, you may not<br />

assign an entire array to another array, or compare entire arrays.<br />

11.7 Uniform and Varying Variables<br />

A renderer implementation may choose to shade many points, or even large regions of a<br />

surface, at once. How large a such a region may be is implementation-dependent.<br />

Shaders contain two classes of variables: uniform variables are those whose values are constant<br />

over whatever portion of the surface is being shaded, while varying variables are<br />

those that may take on different values at different locations on the surface being shaded.<br />

For example, shaders inherit a color and a transparency from the graphics state. <strong>The</strong>se<br />

values do not change from point to point on the surface and are thus uniform variables.<br />

Color and opacity can also be specified at the vertices of geometric primitives (see Section<br />

5, Geometric Primitives). In this case they are bilinearly interpolated across the surface,<br />

and therefore are varying variables.<br />

Local variables and arguments to shaders are declared to be either uniform or varying by<br />

specifying a storage modifier:<br />

varying point p;<br />

uniform point q;<br />

Variables declared in the argument list of a shader are assumed to be uniform variables by<br />

default. <strong>The</strong>se are sometimes referred to as instance variables. If a variable is provided<br />

only when a shader is instanced, or if it is attached to the geometric primitive as a whole,<br />

it should be declared a uniform variable. However, if a variable is to be attached to the<br />

vertices of geometric primitive, it should be declared as a varying variable in the shader<br />

argument list.<br />

Variables declared locally in the body of a shader, as arguments to a function, or as local<br />

variables are assumed to be varying. Declaring a variable to be uniform inside a shader<br />

or function definition is never necessary, but may allow the compiler to generate more<br />

efficient code, particularly for renderer implementations that can shade large regions of a<br />

surface at once.<br />

If a uniform value (or a constant) is assigned to a varying variable or is used in a varying<br />

expression, it will be promoted to varying by duplication. It is an error to assign a varying<br />

value to a uniform variable or to use a varying value in a uniform expression.<br />

118

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

Saved successfully!

Ooh no, something went wrong!