RSL
|
IntroductionThis tutorial develops a bi-directional "occlusionlight" shader that can be used with planar and curved surfaces. Another tutorial, " RSL: Directional Light Source Shaders", introduced a simple directional occlusion light shader - listing 1. The shader works (reasonably) well with planar surfaces that face toward the light but, as can be seen in figure 1, it fails with rear-facing surfaces.
The light source shader is unable to render the directional occlusion properly
for two reasons. First, because it is implemented as a light source it calculates
occlusion only for surfaces that face the light. The second reason concerns
the way that most surface shaders calculate illuminance. Surface shaders
typically set the sampling of their illuminance loop, or loops, to PI/2 and
such hemi-spherical sampling means their rear facing surfaces do not have an
opportunity to perform lighting calculations.
Listing 1 demonstrates the use of the special |
Listing 1 "occlusionlight.sl" - version 1
Listing 2 (occlusiononly.sl)
|
Occlusion for Rear Facing SurfacesThe modified solar() statement shown below illustrates how a shader can determine the direction in which it should sample the occlusion based on the dot product (aka facing-ratio) of the direction vector of the light and the surface normal. solar(direction, 0 ) { dot = normalize(N).normalize(direction); if(dot < 0) direction = -direction; occ = 1 - occlusion(Ps, direction, samples, "coneangle",radians(coneangle)); occ = pow(occ, multiplier); Cl = occ * intensity * lightcolor; }
Unfortunately, the new version of the occclusionlight shader, listing 3, still renders the occlusion improperly - figure 3. Listing 3 "occlusionlight" - version 2
The abrupt darkening of the spheres is caused by 100% occlusion being applied to the micro-polygons that face away from the light - all their occlusion samples hit the floor plane. Although this is the "correct" outcome for strickly directional occlusion, aesthetically, it is objectionable because we expect the occlusion to reach a maximum value only on the parts of the spheres that more directly "face" the floor. |
Attenuating the Sampling Direction and Cone Angle
One solution that will avoid abrupt changes in occlusion involoves biasing the sampling
direction, shown as black arrows in figure 4, toward surface normal as the dot product
approaches 0.0. When the dot product is 1.0 sampling occurs toward the light. When
the dot product becomes -1.0, sampling occurs in the same direction as the light.
The final versions of the light source and surface shaders are shown in listings 4 and 5. Notice the surface shader has parameters that "control" some of the default settings of the light. This enables, for example, objects to individually set the number of occlusion sampling rays. Regrettably, there is a "fudge" factor that must be set to 0 for planar surfaces and 1 for curved surfaces. The parameter "occFudge" of the surface shader enables this factor to be set on an object by object basis.
|
Listing 4 "occlusionlight.sl" - final version
Listing 5 (occlusionsurface.sl)
|
© 2002- Malcolm Kesson. All rights reserved.