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.

}<br />

return 2 * (vector noise(p)) - 1;<br />

Functions may be declared anyplace that it is legal to declare a variable or have any other<br />

language statement, including inside the body of a shader, inside another function, or inside<br />

any other code block. A function may only be called within the lexical scope in which<br />

it is declared, and only after its declaration (the same rules that apply to using a declared<br />

variable). <strong>The</strong> only data that functions may access are those passed as parameters, except<br />

for variables declared with the extern keyword, which indicates that the variable is in an<br />

outer scope rather than that local storage should be allocated. For example:<br />

surface mysurf (float Knoise = 0.5;) /* parameter */<br />

{<br />

color shadernoise (point p)<br />

{<br />

extern float Knoise;<br />

return Knoise * color noise (transform (”shader”, p));<br />

}<br />

}<br />

/* code for the shader */<br />

Ci = shadernoise(P) * diffuse(faceforward(normalize(N),I));<br />

132

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

Saved successfully!

Ooh no, something went wrong!