home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 August / chip_08_2000.iso / aktualnosci / shareware / Rhinoceros / rh11eval_20000320.exe / %MAINDIR% / RIB / shiny.sl < prev    next >
Encoding:
Text File  |  2000-06-08  |  1.3 KB  |  52 lines

  1. /*
  2.  * shiny.sl -- Shiny metal surface, using ray tracing.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes a smoothly polished metal, using ray tracing to calculate
  6.  *   reflections of the environment.
  7.  * 
  8.  * PARAMETERS:
  9.  *    Ka, Kd, Ks, roughness, specularcolor - The usual meaning
  10.  *    Kr - coefficient for mirror-like reflections of environment
  11.  *    blur - how blurry are the reflections? (0 = perfectly sharp)
  12.  *    samples - set to higher than 1 for oversampling of blur
  13.  *
  14.  * AUTHOR: written by Larry Gritz, 1991
  15.  *
  16.  * HISTORY:
  17.  *      Aug 1991 -- written by lg in C
  18.  *      25 Jan 1994 -- recoded by lg in correct shading language.
  19.  *
  20.  * last modified 25 Jan 1994 by Larry Gritz
  21.  */
  22.  
  23.  
  24. #include "rayserver.h"
  25. #include "raytrace.h"
  26.  
  27.  
  28.  
  29. surface
  30. shiny ( float Ka = 1, Kd = 0.5, Ks = 1;
  31.     float Kr = 0.5, roughness = 0.05, blur = 0;
  32.     color specularcolor = 1;
  33.     float samples = 1; )
  34. {
  35.     normal Nf = faceforward (normalize(N), I);
  36.     vector IN = normalize (I);
  37.  
  38.     /* Calculate the reflection color */
  39.     color ev;
  40.     if (Kr > 0.001) {
  41.     vector Rdir = normalize (reflect (IN, Nf));
  42.     ev = Kr * RayTrace (P, Rdir, blur, 1, samples);
  43.     } else {
  44.     ev = 0;
  45.     }
  46.  
  47.     /* The rest is like the plastic shader */
  48.     Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf)) +
  49.      specularcolor * (ev + Ks*specular(Nf,-IN,roughness));
  50.     Oi = Os;  Ci *= Oi;
  51. }
  52.