home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / RCShaders / RCEroded.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  801 b   |  35 lines

  1. /* Listing 16.17  Surface shader eroding the surface of an object*/
  2. /*
  3.  *  eroded(): Simulate a metallic surface eaten away with acid
  4.  */
  5. surface 
  6. RCEroded(    
  7.     float    Ks         = .4, 
  8.         Ka         = .1, 
  9.               Km         = 0.3,
  10.         roughness    = .25 )
  11. {
  12.     float    size        = 4.0, 
  13.         magnitude    = 0.0, 
  14.         i;
  15.     point Nf, 
  16.         W = transform("object", P);
  17.     point x=(1,0,0);
  18.     point V = normalize(-I);
  19.  
  20.     for (i = 0; i < 6.0; i += 1.0) {
  21.         /* Calculate a simple fractal 1/f noise function */
  22.         magnitude += 4.0 * abs(.5 - noise( W*size )) / size;
  23.         size *= 2.0;
  24.     }
  25.  
  26.     /* sharpen peaks */
  27.     magnitude = magnitude * magnitude * magnitude * Km; 
  28.  
  29.     N = calculatenormal( P-magnitude*normalize(N) );
  30.  
  31.     Nf = faceforward(normalize(N), I);
  32.     Oi = smoothstep(0.0001, 0.003, magnitude);
  33.     Ci = Oi * Cs * (Ka*ambient() + Ks*specular(Nf,V,roughness) ) ;
  34. }
  35.