RSL
|
IntroductionThere are many ways that dome-like protrusions can be generated by a displacement shader. This tutorial looks at a couple of procedural techniques that are intended to be a useful basis for a shader that generates water droplets of the type shown shown in figure 1, 2 and 3. |
Figure 1 Figure 2 |
Figure 3 |
This tutorial does not consider displacement mapping techniques nor
does it address issues of how water droplets might be rendered using a
surface shader.
FormulaFigure 4 shows the relationship between a line (chord) that cuts a circle. The cord divides the circle into two parts. The lower portion, labelled S for sagitta measures how much the circle "protrudes" beyond the cord. The height of the gray (right-angled triangle) can be calculated from the theorem of Pythagorus ie. sqrt(R * R - L * L)
Therefore, the sagitta is equal to the radius of the circle less the height of the gray triangle ie. S = R - sqrt(R * R - L * L) |
This formula forms the basis of another formula called the sphereometer formula that derives its name from the instrument that opticians use when they measure the depth of spherical mirrors.
The problem with the sphereometer formula is that it only provides a measure of the sagitta - just a single number. A displacement shader, on the other hand, will require a sequence of numbers (figure 5) that measure the depth of the circle at various distances from the central axis of the "dome". Rather than attempting to adapt the formula, a few short-cuts can be taken that that will enable a rounded dome to be produced even though, strickly speaking, it will have a slightly non-circular profile. |
Squash & Stretch Semi-Circles
If we confine ourselves to a semi-circle of radius "R", then calculating distance "d",
figure 6, for a particular value of "r" again can be done using the theorum
of Pythagorus (note the subtration) ie.
hump = sqrt(R * R - d * d)
If we do not wish to produce semi-circular dome we can apply a scaling factor
(squash/stretch) each time we calculate "d". For our first attempt at applying
this to a displacement shader it will be assumed a dome, centered
in texture space ie. ' |
Listing 1
|
Listing 2
|
Listing 3
|
© 2002- Malcolm Kesson. All rights reserved.