RSL
|
Front ?
The basic code for the RSL listing 1 was taken from Pixar's "Ray-Traced Shading in PRMan"
document. If the users computer has Pixar's documentation installed and
Cutter's
preferences are set correctly
the Rman Tools->QLinks can be used to quickly access
the document.
The simpletrace.sl code in Pixar's doc implements the test for "front facing" as follows. if(n.i < 0) { vector r = reflect(i,n); Ci += trace(P, r); } Figure 2 shows the effect of their shader on a simple scene consisting of two objects (listing 2).
Beware using a Negative TestThe intention of their "if" test,if(n.i < 0) is to ensure the shader only performs a trace from those parts of an object that face the camera ie. front facing surfaces. Yet the test actually asks the question, "is the surface being shaded not a rear face". Even though their "if" test yields the correct results I believe asking, what is in effect, a negative question to be potentially very confusing. Therefore, the sample code (listing 1) uses a slightly modified "if" test. The shader asks the question, "is the surface being shaded a front face"? |
Basic CodeListing 1
|
|
|
Notice in figures 3 and 4 the effect of changing the Option
"maxdepth" from 1 to 2. To see the role played by "big_sphere" place
a comment in front of its Sphere statement. Listing 2
|
What is trace?In the snippet of code shown below the function trace determines the color of the light striking a surface at an angle that is equal and opposite to some input angle - generally based on the camera viewing vector. if(n.-i >= 0) { vector reflectRay = reflect(i, n); reflectcolor = trace(P, reflectRay); } Ci = Os * reflectcolor; } If instead of using the true angle of reflection we apply a little distortion to the vector returned by the reflect() function we get the bumpy effect shown in figure 5. if(n.-i >= 0) { vector reflectRay = reflect(i, n); reflectRay *= noise(P)/2; reflectcolor = trace(P, reflectRay); } Ci = Os * reflectcolor; }
Figure 6 is a close-up of a highly distorted reflection. Note the aliasing artifacts due to the low sampling of the trace rays. To cure this defect we need a version of the trace() function that "looks" in several directions about a region centered on the angle of reflection.
The next function, |
What is gather()
The Surface "gather_mirror" "samples" 12 "samplecone" 0.01 Listing 3
Its difficult to visualize the cone angle measured in radians but
converting radians to degrees (approximately) we have, gather("illuminance", P, reflectDirection,
samplecone, samples, "surface:Cs", hitc)
For each of the (sample) rays the function stores the result in the variable hitc (aka hit color). Notice the shader takes the average by dividing the accumulated color by the number of hits.
|
© 2002- Malcolm Kesson. All rights reserved.