RSL
|
OverviewThis tutorial covers the basics of using the RenderMan Shading Language for the purpose of writing surface shaders. Several shaders are presented that can serve as starting points for the readers own explorations. The reader is encouraged to use the Cutter text editor for shader writing. Details of how it should be set up are given in the tutorial "Cutter Setup: RenderMan Shader Writing". This tutorial develops a series of variations of a basic constant shader. Finally, issues of diffuse lighting are addressed. The shading techniques used in this tutorial do not require ray tracing. |
Assigning a ColorColors may be assigned as a single value (grayscale) or three individual (component) values, for example, color c; /* declare a variable of data type color */ c = 0.8; /* grayscale color */ c = color(0.3, 0.9, 0.5); /* assign a specific color */ "RGB" is the default color space. Listing 1 applies a pale green color to a surface. Listing 1
|
Adding Color Parameters
Two color parameters have been added to listing 2. The Listing 2
The Surface "constant_test2" "Kfb" 1.0 "top" [0.878 0.996 0.474] "lower" [0.580 0.690 0.988]
A color may also be modified by adjusting one of its components ie. setcomp(c, 0, 0.9); /* reset red to 0.9 */
In the example shown above, the function |
Declaring an Array of Color Parameters
A color parameter may also be declared as an array. Listing 3 also uses the 't' texture coordinate
but this time in conjunction with the Listing 3
For simplisity, the declaration of the default color values have been set to white and black
ie color c[4] = {color(1,1,1), color(1,1,0), color(1,0,0), color(0,1,0}
The Surface "spline_test" "Kfb" 1.0 "c" [0.878 0.996 0.474 0.580 0.690 0.988 0.623 0.305 0.658 0.349 0.674 0.427]
Cutter provides a simple color picker to help users interactively define the "rgb" values of a color. To use the picker, select the three values of a color and click the right mouse button (Windows & Linux) or Control + mouse click (MacOSX).
|
Adding Uniform Noise
In this example the Listing 4
The Surface "noise_test1" "Kfb" 1.0 "amp" 0.8 "freq" 9 "top" [0.984 0.976 0.364] "lower" [0.925 0.317 0.317]
To ensure the "jittering" occurs around the mid-point of the range of values generated
by the float ns = abs(noise(s * freq, t * freq) - 0.5);
|
Adding Non-Uniform NoiseThe following shader is similiar to listing 3 except that the two input colors are noisely mixed, more or less uniformly, across a surface. The frequency of the noise in 's' and 't' can be individually controlled - hence the stretching shown in figure 5a. Listing 5
The |
|
|
3D Noise
The previous two shaders generated noise values on the basis of the ' Listing 6
To illustrate what is meant by "3D noise" the shader modifies the apparent opacity of a surface - in effect acting as an irregular "cookie-cutter". To further emphasize the 3D nature of the effect, figure 6 shows a rendering of a stack of square polygons all of which share the "noise_test3" shader.
|
3D Noise & Coordinate Space
The problem with the "noise_test3" shader is that the xyz location of surface point |
|
Th Listing 7
Because the 3D noise is parented to "shader" space, which in this example is effectively the same as "object" space, the irregular holes remain in fixed locations relative to the stack of polygons - figure 7a. |
|
User Defined Coordinates SystemsIn addition to using any of the four predefined space names ie. "camera", "world", "object", and "shader", users can create custom coordinate systems with which they can control a shader. Cutter's Rman Tools palette enables the rib statements that define a coordinate system to be conveniently inserted into a rib file. |
|||
|
TransformBegin Translate 0 0 0 Rotate 0 1 0 0 Rotate 0 0 1 0 Rotate 0 0 0 1 Scale 1 0.25 1 CoordinateSystem "myspace" TransformEnd TransformBegin Surface "constant_test7" "Kfb" 1.0 "freq" 1 "space" ["myspace"] ReadArchive "stack.rib" TransformEnd Using Cutter's drop-down menu to add a custom coordinate system to a rib file and accessing the custom coordinate system via the shaders "space" parameter. |
|
Figure 7c shows the effect of scaling a user-defined coordinate system named "myspace". |
Diffuse Illumination
The next set of shaders calculate the color of the diffuse illumination on a micro-polygon.
The diffuse, also known as Lambert, illumination is derived from the angle between the surface
normal and the (incident) ray of light striking a surface. When a micro-polygon directly "faces"
the incident light it receives maximum illumination. When its normal makes an oblique angle to
the incident light the illumination on the micro-polygon diminishes (drops off) in proportion
to the cosine of the angle.
Listing 8
The normal n = normalize(N); normal nf = faceforward(n, I); |
|
Cartoon Shading
High contrast or cartoon-like lighting can be obtained by thresholding the
diffuse illumination. In the rendering shown in figure 9 values of diffuse
less than 0.5 are treated as if they were black. Values slightly higher ie.
adjusted by the "blur" parameter, are considered to be white. Using the
Listing 9a
|
|
|
As a variation of the cartoon "theme" the next shader, listing 9b, applies a
repeating pattern to the threshold to produce a series of bands. For more
information about the use of the Listing 9b
|
Inside/Outside ShadingBy comparing the normalized copy of the surface normal (N) with the normal returned by the faceforward() function it is possible to decide whether the shader is currently processing a micro-polygon of the front or the (inside of the) rear surface of an object. Using this if-the-normal-been-flipped technique it is possible to create some interesting effects. Listing 10 demonstrates how "front" and "rear" colors can be applied to geometry. Listing 10
|
|
High Contrast Shading
Some unusual visual effects can be obtained by combining the high contrast shading of listings
9a/9b with the diffuse shading of listing 8. The next shader, listing 11, uses the high contrast
values to alter the apparent opacity of a surface. In effect, the shader causes the light that
strikes a surface to behave like a "cookie-cutter". However, the apparent surface color is not
effected by the high contrast but instead is shaded by the color returned from the Listing 11
|
|
Texture Mapping
When a surface is texture mapped the '
With the introduction of Pixar's RenderMan Studio (RMS) the situation with regard to the
relative orientation of '
The surfaces shown above can be accessed as pre-baked ribs via the RMan Tools menu - figure 12c. Copies of the pre-baked ribs can be opened using the Templates menu - figure 12d. |
|||
Selecting ReadArchive "nCylinder.rib" |
|
Reading Texture Maps for Surface Coloration
The majority of RenderMan complient renderers do not directly use an image file
for texture mapping but insted require the file to be converted to a
texture file. Texture files contain representations of the original image at different
scales. During convertion the pixel data in the texture file is filtered and this,
combined with the texture files multiple images (mip maps), results in the renderer
being able to perform efficient anti-aliased texturing.
|
|||
|
|
Rather than using the Texture Tool it is often more
convenient to execute a
line of text. For example, selecting the following line of text and using the
keyboard short cut Alt+e, Control+e or Apple+e is the same as
executing the
A comment at the beginning of a line is ignored when Cutter executes the text. Text may also be broken over sever lines.
Listing 12 provides the code for the texture mapping shader used to render figure 12g. |
Listing 12
|
Using a Texture Map for Surface Opacity
The |
|||||
|
|
||||
Listing 13
|
To ensure an opacity mapper, such as if(texname != "") { color c = texture(texname); float ave = (comp(c, 0) + comp(c, 1) + comp(c, 2))/3; Oi = ave * Os; } |
© 2002- Malcolm Kesson. All rights reserved.