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.

Section 16<br />

EXAMPLE SHADERS<br />

16.1 Surface Shaders<br />

Surface shaders inherit the surface variables of the surfaces to which they are attached. A<br />

surface shader should always set the output color Ci and optionally the output opacity Oi<br />

that is emitted in the direction -I. I is the direction of the ray incident to the surface. <strong>The</strong><br />

length of this vector is equal to the distance between the origin of the ray and the point on<br />

the surface. Thus the actual origin of the ray is available as P-I.<br />

16.1.1 Turbulence<br />

<strong>The</strong> following surface shader implements a simple turbulence procedural texture. <strong>The</strong><br />

shader computes the texture by adding various octaves of noise, weighting each octave<br />

by 1/f, where f is the cutoff frequency of that octave. This texture is then used to modulate<br />

the opacity of the surface. <strong>The</strong> texture is generated in the named coordinate system<br />

”marble”, which must have been established with by the use of an RiCoordinateSystem<br />

(”marble”) call before the instantiation of the turbulence shader. Notice that after the opacity<br />

has been computed, it is multiplied into the color, so that the colors and opacities output<br />

by the shader are premultiplied for use by pixel compositors.<br />

surface<br />

turbulence ( float Kd=.8, Ka=.2 )<br />

{<br />

float a, scale, sum ;<br />

float IdotN;<br />

point M; /* convert to texture coordinate system */<br />

M = transform( ”marble”, P );<br />

scale = 1;<br />

sum = 0;<br />

a = sqrt(area(M));<br />

while( a < scale ) {<br />

sum += scale * float noise(M/scale);<br />

scale *= 0.5;<br />

}<br />

151

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

Saved successfully!

Ooh no, something went wrong!