RSL
|
IntroductionThis tutorial outlines the steps taken in developing a shader creates a simple rosette pattern - figure 1. The RSL code is given in listing 3.
The technique is based on the observation that each triangular "spoke" of the rosette is, diagonally, half of a rectangle - figure 2.
It is far easier to test whether an 'st' location is within the half diagonal, shown in red,
if it's enclosing rectangle is "moved" to the origin of the texture coordinate system.
Put another way, it is always
easier to test the interior of shape when it is in its cannonical position ie. at
the origin of the ('st') coordinate system.
Step 1 - Diagonal
Figures 2 and 3 shows a 1x1 'st' texture space. Notice the micropolygons in the area outlined
in blue share this relationship with respect to their 's' and 't' texture coordinates.
The relationship can also be expressed as,
|
Listing 1 - diagonal.sl
|
Step 2 - TriangleTo create a single triangle located at s = 0.6, t = 0.5 the 'st' coordinates are given corresponding offsets. Additionally, using the absolute value (abs()) of the offset 't' ensures the "mirrored" half of the offset triangle is also rendered. |
Listing 2 - triangle.sl
|
Step 3 - Radial RepititionsThe final step in creating the rosette pattern is to rotate the current 'st' location in increments equal to the angle that separates the "spokes" of the pattern and for each rotated 'st' location perform the "triangle" test. |
Listing 3 - rosette.sl
© 2002- Malcolm Kesson. All rights reserved. |