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_skymetal.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.2 KB  |  46 lines

  1. /* skymetal shader 
  2.  * from p. 103 of Siggraph 1991 Course 21
  3.  * The RenderMan Interface and Shading Language
  4.  *
  5.  * NOTE: This shader was created at a time when the shading lanuage
  6.  *   didn't support vector the vector type.  
  7.  *
  8.  * A more general version with some explainations can be found in my
  9.  * TLSkymetal shader.  Actually, I never could get this oneto work right,
  10.  * anyways.
  11.  *
  12.  * tal@SpamSucks_cs.caltech.edu
  13.  */
  14.  
  15. surface k3d_skymetal (
  16.   float Ka = 1, Ks = 1, Kr = .2;
  17.   float roughness = .1;
  18.     point up = normalize (point "world" (0, 1, 0) - point "world"  (0, 0, 0)); 
  19.              /* actually should be vector and vtransform if using 3.5 or 
  20.                 greater */
  21.  
  22. )
  23. {
  24.     point Nf;
  25.     color refl;
  26.     float costheta;
  27.     
  28.     color sky_zenith = color (0.125, 0.162, 0.5);
  29.     color sky_horiz = color (.4, .45, .8);
  30.     color land_horiz = color (.0281, 0.0287, 0.0220);
  31.     color land_zenith = color (0, 0, 0);
  32.     
  33.     Nf = normalize (faceforward (N, I));
  34.  
  35.     costheta = normalize (reflect (I, Nf)) . up;
  36.  
  37.     if (costheta >= 0.0)
  38.         refl = mix (sky_horiz, sky_zenith, costheta);
  39.     else 
  40.         refl = mix (land_horiz, land_zenith, -costheta);
  41.         
  42.     Oi = Os;    
  43.     Ci = Os * Cs * (Kr*refl + (1-Kr) * (Ka * ambient () +
  44.         Ks * specular (Nf, -I, roughness)));
  45. }
  46.