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

  1. // rh.glass -- a custom glass shader with fake caustic shadow.
  2. // In this shader the RIB surface color determines the glass color and
  3. // the glass surface itself has no color.
  4. // It is based on glass.sl by Larry Gritz.
  5.  
  6. #include "locillum.h"
  7. #include "rayserver.h"
  8. #include "raytrace.h"
  9.  
  10. surface
  11. rh_glass ( float Ka = 0.2, Kd = 0, Ks = 0.5;
  12.   float Kr = 1, Kt = 1, roughness = 0.05;
  13.   float reflectblur = 0, refractblur = 0, eta = 1.5;
  14.   color specularcolor = 1;
  15.   float samples = 1; )
  16. {
  17.     color ev = 0;            /* Color of the environment reflections */
  18.     color cr = 0;            /* Color of the refractions */
  19.  
  20.     vector IN = normalize (I);
  21.     normal Nf = faceforward (normalize(N), I);
  22.  
  23.     /* Compute the reflection & refraction directions and amounts */
  24.     vector Rfldir, Rfrdir;   /* Smooth reflection/refraction directions */
  25.     float kr, kt;
  26.     fresnel (IN, Nf, (I.N < 0) ? 1.0/eta : eta, kr, kt, Rfldir, Rfrdir);
  27.     kr *= Kr;
  28.     kt *= Kt;
  29.  
  30.     /* Calculate the reflection color */
  31.     if (kr > 0.001) {
  32.     ev = kr * RayTrace (P, normalize(Rfldir), reflectblur, 1, samples);
  33.     }
  34.  
  35.     /* Calculate the refraction color */
  36.     if (kt > 0.001) {
  37.     cr = kt * RayTrace (P, normalize(Rfrdir), refractblur, 1, samples);
  38.     }
  39.  
  40.     if ( isshadowray() > 0 ) {
  41.       Oi = Os * (1 - abs(IN.Nf) * Cs); /* fake caustics */
  42.     } else {
  43.       Oi = 1;
  44.       Ci = ( (Ka*ambient() + Kd*diffuse(Nf)) +
  45.       specularcolor * (ev + Ks*LocIllumGlossy(P,Nf,-IN,roughness,0.5)) +
  46.       Cs * cr );
  47.     }
  48. }
  49.