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

  1. /*
  2.  * veinedmarble.sl -- surface shader for a nice veined marble.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes solid marble texture with strong veins.  The "veincolor" parameter
  6.  *   controls the color of the veins.  The background color is given by the
  7.  *   surface color (Cs).
  8.  * 
  9.  * PARAMETERS:
  10.  *   Ka, Kd, Ks, roughness, specularcolor - same as plastic
  11.  *   veinfreq - controls fhe lowest frequency of the color veins
  12.  *   veinlevels - how many "levels" of vein tendrills it has
  13.  *   warpfreq - lowest frequency of the turbulent warping in the marble
  14.  *   warping - controls how much turbulent warping there will be
  15.  *   veincolor - the color of the veins
  16.  *   sharpness - controls how sharp or fuzzy the veins are (higher = sharper)
  17.  *
  18.  *
  19.  * AUTHOR: Larry Gritz, the George Washington University
  20.  *         email: gritz@seas.gwu.edu
  21.  *
  22.  * HISTORY:
  23.  *
  24.  * last modified  29 Jun 1994 by Larry Gritz
  25.  */
  26.  
  27.  
  28.  
  29.  
  30.  
  31. surface
  32. LGVeinedMarble (float Ka = .5;
  33.           float Kd = .8;
  34.           float Ks = .4;
  35.           float roughness = .005;
  36.           color specularcolor = 1;
  37.           float veinfreq = 1;
  38.           float veinlevels = 2;
  39.           float warpfreq = 1;
  40.           float warping = .5;
  41.           color veincolor = color(.6,.5,.1);
  42.           float sharpness = 8;
  43.              )
  44. {
  45. #define snoise(x) (2*noise(x)-1)
  46.   color Ct;
  47.   point Nf;
  48.   point PP, offset;
  49.   float i, turb, freq, j;
  50.   float turbsum;
  51.  
  52.   PP = transform ("shader", P);
  53.  
  54.   /* perturb the lookup */
  55.   freq = 1;
  56.   offset = 0;
  57.   for (i = 0;  i < 6;  i += 1) {
  58.       offset += 2 * warping * (point noise (warpfreq * freq * PP) - 0.5)  / freq;
  59.       freq *= 2;
  60.     }
  61.   PP += offset;
  62.  
  63.   /* Now calculate the veining function for the lookup area */
  64.   turbsum = 0;  freq = 1;
  65.   PP *= veinfreq;
  66.   for (i = 0;  i < veinlevels;  i += 1) {
  67.       turb = abs (snoise (PP));
  68.       turb = pow (smoothstep (0.8, 1, 1 - turb), sharpness) / freq;
  69.       turbsum += (1-turbsum) * turb;
  70.       freq *= 3;
  71.       PP *= 3;
  72.     }
  73.  
  74.   Ct = mix (Cs, veincolor, turbsum);
  75.  
  76.   Oi = Os;
  77.   Nf = faceforward (normalize(N),I);
  78.   Ci = Os * ( Ct * (Ka*ambient() + Kd*diffuse(Nf)) +
  79.           specularcolor * Ks*specular(Nf,-normalize(I),roughness));
  80. }
  81.