RSL
|
IntroductionThere are occasions when a shader will not use 's' and 't' directly but will, instead, use rotated copies of them so that, for example, a texture map or a procedural pattern can be pivoted around a point defined in texture space - figures 1 and 2. |
|
|
This tutorial shows how the
built-in RSL function |
Listing 1 (simpleTex.sl)
Listing 2 applies the shader to a polygon, the result of which is shown in figure 1. Listing 2 (simpleTex.rib)
|
Note 1
|
If Cutter's RenderMan preferences have been set correctly, the editor will automatically
add the |
||
Note 2
|
The line of code shown in red in listing 2 can be executed, as if it were
entered into a command window (Windows) or a terminal (Linux/MacOSX), by selecting it
and pressing alt + e, control + e or Apple + e. The directories in which the source
tiff file and the output texture file are located are assumed to be one level above
Cutter's working directory.
Alternatively, |
Using the RSL rotate() FunctionBecause the rotate() function operates on 3D points, the 2D 'st' texture coordinates referenced within a shader must be converted to their 3D equivalent. If a shader allows a user to specify a pivot point in 'st' space, for example, Surface "rotateTex" "Kd" 1.0 "texname" ["IMAGE.tex"] "pivot_s" 0.5 "pivot_t" 0.5 "angle" 45 using the rotate() function is reasonably straight forward - listing 3. Listing 3 (rotateTex.sl)
|
However, if a shader enables a user to directly define the axis of rotation, by specifying two 3D points ie. Surface "rotateTex" "Kd" 1.0 "texname" ["swazi.tex"] "pnt1" [0 0 0] "pnt2" [0 1 0] "angle" 45 the use of rotate() is less intuitive. Passing pnt1 and pnt2 directly to the rotate() function ie. point stPnt = point(s, 0, t); point stRot = rotate(stPnt, radians(angle), pnt1, pnt2); will not yield the correct rotation. Listing 4 provides the code for a shader that ensures that points pnt1 and pnt2 are transformed to a user defined coordinate system. By default it is assumed x,y,z values of the points are measured from the origin of the object's coordinate system. |
Listing 4 (rotateTex2.rib)
Section "3D Noise & Coordinate Space" of the tutorial
"RSL: Writing Surface Shaders"
addresses the issue of using the |
A User Defined FunctionListing 5 provides the code for a function that encapsulates the conversion of the 'st' coordinates and the center of rotaion to 3D points. Listing 5 (rotations.h)
If the function is saved as, say, Listing 6 (modified rotateTex.sl)
|
© 2002- Malcolm Kesson. All rights reserved.