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_spaceshiphull1.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.1 KB  |  55 lines

  1. #include "k3d_noises.h"
  2.  
  3.  
  4. float fractalsum(point Q)
  5. {
  6.     float f;
  7.     float value = 0;
  8.  
  9.     for(f = 1; f < 8; f *= 2)
  10.         value += snoise(Q * f) / f;
  11.  
  12.     return value;
  13. }
  14.  
  15.  
  16.  
  17. surface k3d_spaceshiphull1(
  18.     float Ka = 1;
  19.     float Kd = 1;
  20.     float Ks = 0.25;
  21.     float roughness = 0.8; color specularcolor = 1;
  22.     float width = .1; float height = .06;
  23.     float lumavary = .4;
  24.     float rowvary = 3.0;
  25.     float grime = 0.1)
  26. {
  27.   float ss, tt, splate, tplate, platespecular;
  28.   color platecolor;
  29.   point Nf;
  30.   point V;
  31.  
  32.   // Figure out which row we're in  
  33.   ss = s / width;
  34.   tt = t / height;
  35.  
  36.   tplate = floor(tt);
  37.  
  38.   ss += rowvary * noise(tplate + 0.3);
  39.   splate = floor(ss);
  40.  
  41.   // Calculate plate color
  42.   platecolor = Cs - (lumavary * float noise(splate + 0.4, tplate + 0.5));
  43.  
  44.   // Add grime
  45.   platecolor -= grime * fractalsum(P);
  46.  
  47.   // Add specular contribution
  48.   platespecular = Ks * noise(splate + 0.6, tplate + 0.7);
  49.  
  50.   Nf = faceforward(normalize(N), I);
  51.   V = normalize(-I);
  52.   Oi = Os;
  53.   Ci = Os * platecolor * (Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * platespecular * specular(Nf, V, roughness);
  54. }
  55.