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

  1. /* Renamed to SHW_velvet.sl -- tal@cs.caltech.edu */
  2.  
  3. /*
  4.  * velvet.sl -- velvet
  5.  *
  6.  * DESCRIPTION:
  7.  *   An attempt at a velvet surface.
  8.  *   This phenomenological model contains three compnents:
  9.  *   - A retroreflective lobe (back toward the light source)
  10.  *   - Scattering near the horizon, regardless of incident direction
  11.  *   - A diffuse color
  12.  * 
  13.  * PARAMETERS:
  14.  *   Ks:    controls retroreflective lobe
  15.  *   Kd:    scales diffuse color
  16.  *   Ka:    ambient component (affects diffuse color only)
  17.  *   sheen:    color of retroreflective lobe and horizon scattering
  18.  *   roughness: shininess of fabric (controls retroreflection only)
  19.  *   Cs:    diffuse color
  20.  *
  21.  * ANTIALIASING: should antialias itself fairly well
  22.  *
  23.  * AUTHOR: written by Stephen H. Westin, Ford Motor Company
  24.  *
  25.  * HISTORY:
  26.  *
  27.  * last modified  28 January 1997 S. H. Westin
  28.  */
  29.  
  30. #define SQR(A) ((A)*(A))
  31.  
  32. surface
  33. SHW_velvet (float Ka = 0.05,
  34.               Kd = 0.1,
  35.           Ks = 0.1;
  36.     color sheen = .25;
  37.     float roughness = .1;
  38.   )
  39. {
  40.   point Nf;             /* Normalized normal vector */
  41.   vector V;             /* Normalized eye vector */
  42.   vector H;             /* Bisector vector for Phong/Blinn */
  43.   vector Ln;             /* Normalized vector to light */
  44.   color shiny;             /* Non-diffuse components */
  45.   float cosine, sine;         /* Components for horizon scatter */
  46.  
  47.   Nf = faceforward (normalize(N), I);
  48.   V = -normalize (I);
  49.  
  50.   shiny = 0;
  51.   illuminance ( P, Nf, 1.57079632679489661923 /* Hemisphere */ ) {
  52.     Ln = normalize ( L );
  53.     /* Retroreflective lobe */
  54.     cosine = max ( -Nf.V, 0 );
  55.     shiny += pow ( cosine, 1.0/roughness ) / ( Ln.Nf ) * Cl * sheen;
  56.     /* Horizon scattering */
  57.     cosine = max ( Nf.V, 0 );
  58.     sine = sqrt (1.0-SQR(cosine));
  59.     shiny += pow ( sine, 10.0 ) * Ln.Nf * Cl * sheen;
  60.   }
  61.  
  62.   Oi = Os;
  63.   /* Add in diffuse color */
  64.   Ci = Os * (Ka*ambient() + Kd*diffuse(Nf)) * Cs + shiny;
  65.  
  66. }
  67.