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

  1. /*
  2.  * outlet.sl -- surface shader for an electrical outlet
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes an electrical outlet.  Perfect for slapping on a bilinear
  6.  *   patch to make a wall more interesting.  The patch should be
  7.  *   twice as high as it is wide.  *Totally* cheesy if you see it from
  8.  *   up close, but from across the room, it's a nice touch of detail.
  9.  *   I should probably add some bump mapping or other variation, but
  10.  *   I'm lazy, okay?
  11.  * 
  12.  * PARAMETERS:
  13.  *   Ka, Kd            work just like the matte shader
  14.  *   screwKs            Ks parameter for the screw
  15.  *
  16.  *
  17.  * AUTHOR: written by Larry Gritz
  18.  *
  19.  * HISTORY:
  20.  *      June 1992 -- first written by lg for the Kitchen image
  21.  *      17 Jan 1994 -- recoded by lg in correct shading language.
  22.  *
  23.  * last modified  17 Jan 1994 by Larry Gritz
  24.  */
  25.  
  26.  
  27.  
  28. surface
  29. k3d_outlet ( float Ka = 1, Kd = 1, Km = 0.1;
  30.      float screwKs = 0.5; )
  31. {
  32.   color Ct;
  33.   float x, y;
  34.   float ks, kd, roughness;
  35.   point Nf;
  36.   
  37.   /* defaults */
  38.   kd = Kd;
  39.   ks = 0;
  40.   roughness = 0.25;
  41.   Ct = Cs;
  42.  
  43.   x = abs (u - 0.5);
  44.   y = 2 * v;
  45.  
  46.   if ((x*x + (y-1)*(y-1)) < 0.0025) {
  47.       Ct = Cs * 0.5;
  48.       ks = screwKs;
  49.       kd = 0;
  50.     }
  51.   else if (x > 0.08  &&  x < 0.14  &&
  52.        ((y > 0.42 && y < 0.62) || (y > 1.22 && y < 1.42)))
  53.     {
  54.       Ct = 0.1 * Cs;
  55.     }
  56.   else if (x < 0.25  &&  ((y > 0.35 && y < 0.85) || (y > 1.15 && y < 1.65))) {
  57.       if (((x*x + (y-0.75)*(y-0.75)) < 0.0025) ||
  58.       ((x*x + (y-1.55)*(y-1.55)) < 0.0025)) {
  59.       Ct = 0.1 * Cs;
  60.     }
  61.       else {
  62.       Ct = 0.75 * Cs;
  63.     }
  64.     }
  65.  
  66.  
  67.   /* Use the plastic illumination model */
  68.   Nf = faceforward (normalize(N),I);
  69.   Oi = Os;
  70.   Ci = Os * ( Ct * (Ka*ambient() + kd*diffuse(Nf)) +
  71.           ks * specular(Nf,-normalize(I),roughness));
  72.  
  73. }
  74.