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.

Shader instance variable values can be changed from their defaults by passing their new<br />

values through the <strong>RenderMan</strong> <strong>Interface</strong>. This first requires that the type of the variable be<br />

declared. <strong>The</strong> declaration for weird would be:<br />

RiDeclare( ”a”, ”uniform float” );<br />

RiDeclare( ”b”, ”varying float” );<br />

Of course, the RiDeclare can be eliminated if “in-line declarations” are used (see Section 3).<br />

In either case, uniform instance variables can be set by passing them in the parameterlist of<br />

a shader instance. In the following example, a is redefined while b remains equal to its<br />

default:<br />

RtFloat a = 0.3;<br />

RiSurface( ”weird”, ”a”, (RtPointer)&a, RI NULL );<br />

Shader variables can also be set in geometric primitives. For example, the weird shader<br />

variables could be set when defining a primitive:<br />

RtFloat a;<br />

RtFloat bs[4];<br />

RtPoint Ps[4];<br />

RiPolygon(4, ”P”, Ps, ”a”, (RtPointer)&a, ”b”, (RtPointer)bs, RI NULL)<br />

a is a single float and b is an array containing four values, since it is a varying variable. <strong>The</strong><br />

standard variable ”P” is predeclared to be of type varying point.<br />

If a geometric primitive sets a shader variable that is defined in none of the shaders associated<br />

with that primitive, it is ignored. Variables that are set on geometric primitives<br />

override the values set by the shader instance.<br />

Shader instance variables are read-only in the body of the shader, unless they are declared<br />

using the output keyword:<br />

displacement<br />

lumpy ( float a=0.5; output varying float height=0 )<br />

{<br />

float h = a * noise(P);<br />

P += h * normalize(N);<br />

N = calculatenormal(N);<br />

height = h;<br />

}<br />

This displacement shader produces a lumpy surface and also saves the displacement amount<br />

in an output variable height. Output variables of one shader may be read by other shaders<br />

on the same primitive (see Section 15.8) in order to pass information between them.<br />

130

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

Saved successfully!

Ooh no, something went wrong!