home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / light / k3d_shadowspot.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.1 KB  |  36 lines

  1. /* Copyrighted Pixar 1989 */
  2. /* From the RenderMan Companion p.380 */
  3. /* Listing 16.33  Spotlight using shadow map*/
  4.  
  5. /*
  6.  *  shadowspot(): spotlight with an optional shadow map
  7.  */
  8. light k3d_shadowspot( 
  9.     float intensity    = 1;
  10.     color lightcolor = 1;
  11.     point from = point "shader" (0, 0, 0);
  12.     point to = point "shader" (0, 0, 1);
  13.     float coneangle    = radians(30);
  14.     float conedeltaangle = radians(5);
  15.     float beamdistribution = 2;
  16.     string shadowfile = "";
  17.     float samples = 16;
  18.     float blur = 0.01;
  19.     float bias = 0.01; )
  20. {
  21.     point A = (to - from) / length(to - from); /* direction */
  22.     float    cosoutside= cos(coneangle),
  23.             cosinside = cos(coneangle-conedeltaangle);
  24.     float    attenuation,     /* falloff from center of illumination cone */
  25.         cosangle;    /* cosine of angle wrt center of cone */
  26.  
  27.     illuminate( from, A, coneangle ) {
  28.         cosangle = L.A / length(L);    /* A is already normalized */
  29.         attenuation = pow(cosangle, beamdistribution) / (L.L);
  30.         attenuation *= smoothstep( cosoutside, cosinside, cosangle );
  31.         if( shadowfile != "" )
  32.             attenuation *= (1.0 - shadow( shadowfile, Ps, "samples", samples, "blur", blur, "bias", bias ));
  33.         Cl = attenuation * intensity * lightcolor;
  34.     }
  35. }
  36.