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

  1. /* rh_brushedmetal - uses surface color
  2.  
  3. /* Renamed to LGbrushedmetal for RMR -- tal@cs.caltech.edu */
  4.  
  5. /*
  6.  * Greg Ward Larson's anisotropic specular local illumination model.
  7.  * The derivation and formulae can be found in:  Ward, Gregory J.
  8.  * "Measuring and Modeling Anisotropic Reflection," ACM Computer
  9.  * Graphics 26(2) (Proceedings of Siggraph '92), pp. 265-272, July, 1992.
  10.  * Inputs:
  11.  *   N - unit surface normal
  12.  *   V - unit viewing direction (from P toward the camera)
  13.  *   xdir - a unit tangent of the surface which defines the reference
  14.  *          direction for the anisotropy.
  15.  *   xroughness - the apparent roughness of the surface in xdir.
  16.  *   yroughness - the roughness for the direction of the surface
  17.  *          tangent which is perpendicular to xdir.
  18.  */
  19. color
  20. LocIllumWardAnisotropic (normal N;  vector V;
  21.                          vector xdir;  float xroughness, yroughness;)
  22. {
  23.     float sqr (float x) { return x*x; }
  24.  
  25.     float cos_theta_r = clamp (N.V, 0.0001, 1);
  26.     vector X = xdir / xroughness;
  27.     vector Y = (N ^ xdir) / yroughness;
  28.  
  29.     color C = 0;
  30.     extern point P;
  31.     illuminance (P, N, PI/2) {
  32.         /* Must declare because extern L & Cl because we're in a function */
  33.         extern vector L;  extern color Cl;
  34.         float nonspec = 0;
  35.         lightsource ("__nonspecular", nonspec);
  36.         if (nonspec < 1) {
  37.             vector LN = normalize (L);
  38.             float cos_theta_i = LN . N;
  39.             if (cos_theta_i > 0.0) {
  40.                 vector H = normalize (V + LN);
  41.                 float rho = exp (-2 * (sqr(X.H) + sqr(Y.H)) / (1 + H.N))
  42.                     / sqrt (cos_theta_i * cos_theta_r);
  43.                 C += Cl * ((1-nonspec) * cos_theta_i * rho);
  44.             }
  45.         }
  46.     }
  47.     return C / (4 * xroughness * yroughness);
  48. }
  49.  
  50.  
  51.  
  52. surface
  53. rh_brushedmetal ( float Ka = 1, Kd = 0.1, Ks = .9;
  54.         float uroughness = 0.35, vroughness = 0.2; 
  55. )
  56. {
  57.     normal Nf = faceforward (normalize(N), I);
  58.     vector xdir = normalize (dPdu);
  59.  
  60.     color spec = LocIllumWardAnisotropic (Nf, -normalize(I),
  61.                                           xdir, uroughness, vroughness);
  62.     Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf) + Ks*spec);
  63.     Oi = Os;  Ci *= Oi;
  64. }
  65.  
  66.