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

  1. /* Copyrighted Pixar 1989 */
  2. /* From the RenderMan Companion p.351 */
  3. /* Listing 16.15  Surface shader providing wood-grain texture */
  4.  
  5. /*
  6.  * wood(): calculate a solid wood texture using noise()
  7.  *
  8.  */
  9. surface
  10. wood (
  11.     float ringscale = 10;
  12.     color lightwood = color (0.3, 0.12, 0.03),
  13.           darkwood  = color (0.05, 0.01, 0.005);
  14.     float Ka        = 0.2,
  15.           Kd        = 0.4,
  16.           Ks        = 0.6,
  17.           roughness = 0.1)
  18. {
  19.     point NN, V;
  20.     point PP;
  21.     float y, z, r;
  22.     
  23.     /* 
  24.      * Compute the forward-facing normal NN and the vector
  25.      * toward the ray orgigin V, both normalized.
  26.      * These vectors are used by "specular" and "diffuse". */
  27.     NN = faceforward(normalize (N), I);
  28.     V = -normalize(I);
  29.     
  30.     PP = transform("shader", P);
  31.     PP += noise(PP);
  32.     
  33.     /* compute radial distance r from PP to axis of "tree" */
  34.     y = ycomp (PP);
  35.     z = zcomp (PP);
  36.     r = sqrt (y*y + z*z);
  37.     
  38.     /* map radial distance r nto ring position [0, 1] */
  39.     r *= ringscale;
  40.     r += abs (noise(r));
  41.     r -= floor (r);         /* == mod (r, 1) */
  42.     
  43.     /* use ring poisition r to select wood color */
  44.     r = smoothstep (0, 0.8, r) - smoothstep (0.83, 1.0, r);
  45.     Ci = mix(lightwood, darkwood, r);
  46.     
  47.     /* shade using r to vary shininess */
  48.     Oi = Os;
  49.     Ci = Oi * Ci * (Ka * ambient() + Kd * diffuse(NN))
  50.      + (0.3 * r + 0.7) * Ks * specular (NN, V, roughness);
  51. }
  52.