/* The code for handling shadow maps was duplicated in the tebPointLight
 *    and tebSpotLight.  With the addition of tebLaserLight and tebLensLight,
 *    I've moved the shadow code to one location.
 */
float tebShadow( string shadowmap;
		 point Ps;
		 float shadowmapopacity;
		 float shadowsamples;
		 float shadowblur;
		 float shadowbias )
{
   float attenuation = 1.0;


   /* In PRMan 3.7 functions are inlined, so the if(shadowmap!="") being in
    *    the function shouldn't be an inefficiency in the shader.
    */
   if ( shadowmap != "" )
   {
      /* The PRMan 3.6 docs mention a new parameter for shadow() 
       *    called bias that appears to replace the averaging scheme 
       *    using bias0 and bias1 with the value bias.  
       * Why two shadow() function calls?
       *    If you set shadowbias to zero, the shader will use the default
       *    algorithm for handling bias.  The docs don't mention anything 
       *    about bias being ignored if it is set to zero, so the only way I
       *    can think to implement this is to have two shadow() calls:
       *    the first call to shadow() is with a bias value and the 
       *    second shadow() call is without a bias parameter.  The 
       *    value bias is checked to determine which of the two shadow() 
       *    calls to use.
       * Using an "if" is OK here because bias is not a varying 
       *    parameter.  It is a uniform parameter.
       * The shadowblur value appears to simply be what is commonly
       *    given the name "width" in the shader shadowspot.sl.
       */
      if (shadowbias==0)
      {
	 /* Point P is where the spotlight is.  Point Ps is the point
	  *   on the surface being illuminated.  Refer to the 
	  *   descriptions above for the other parameters given to 
	  *   shadow().
	  */
	 attenuation = (1.0 - shadow( shadowmap, Ps, 
				      "samples", shadowsamples,
				      "swidth", shadowblur, 
				      "twidth", shadowblur ));
      }
      else
      {
	 attenuation = (1.0 - shadow( shadowmap, Ps, 
				      "samples", shadowsamples,
				      "swidth", shadowblur, 
				      "twidth", shadowblur,
				      "bias", shadowbias));
      }
      attenuation *= shadowmapopacity;
   }

   return attenuation;
}

[Affine Toolkit]
[RIB Utilities] [Bitmap Utilities] [Handy Little Utilities]
[Libraries] [Using the Libraries]