home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / surface / k3d_scartissue.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  914 b   |  37 lines

  1. /*  IDscartissue.sl written by Ivan DeWolf
  2.  *  an unremarkable recursive noise to make scartissue
  3.  *  feel free to copy, distribute, hack and/or abuse this code 
  4.  *  in any way you see fit, but please leave my name near the top
  5.  */
  6. surface
  7. k3d_scartissue(
  8.     float    Ks            =  2, 
  9.         Kd            = .5, 
  10.         Ka            =  1, 
  11.         roughness        = .2; 
  12. )
  13. {
  14.     point Psh = transform("object",P);
  15.     uniform float i, freq = 2.0, offset = 0;
  16.     float nz = 0;
  17.     color light = color (1,.3,.2);
  18.     color dark = color (.015,.02,.02);
  19.     color base;
  20.     normal Nn = normalize(N);
  21.     normal Nf = faceforward(normalize(N), I );
  22.     vector V = normalize(-I);
  23.  
  24.     for (i = 0; i < 10; i = i + 1) {
  25.         nz += abs(.5 - noise( (freq * Psh)+offset)) / freq;
  26.         freq *= 1.2;
  27.         offset += 10;
  28.     }
  29.     base = mix(dark,light,nz);
  30.     P += Nn*nz*.3;
  31.     N = calculatenormal(P);
  32.     Nf = faceforward(normalize(N), I );
  33.  
  34.     Ci = ( base * (Ka + Kd*diffuse(Nf)) + 
  35.          (1-nz)*Ks * specular(Nf,V,roughness) );
  36. }
  37.