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

  1. /* 
  2.  * Again, similar structure of grass.sl
  3.  *
  4.  *  by Lawrence D. Chin, cs184-bo
  5.  */
  6.  
  7. #include "k3d_rmannotes.h"
  8.  
  9. surface
  10. k3d_grass_surface ( float height = 1.0, Ka=0.5, Kd=0.1, Ks= 1, roughness = 0.25,
  11.               fac = 1.0,
  12.               size = 1.0,
  13.           size2 = 0.75; )
  14. {
  15.  
  16.   color color1 = color(0,1,0), color2 = color(0.5,0.5,0);
  17.   point Nf = faceforward(normalize(N),I);
  18.  
  19.   float noifreq = 5;
  20.   float noiscale = 0.4;
  21.   float ss, tt;
  22.  
  23.   float noi = noise(s * noifreq, t * noifreq);
  24.   ss = s + snoise(noi + 912) * noiscale;
  25.   tt = t + snoise(noi + 333) * noiscale;
  26.  
  27.   float smod = mod(ss*fac,1),
  28.         tmod = mod(tt*fac,1);
  29.  
  30.   if (smod > tmod) {
  31.     if (smod < 0.5) {
  32.       float d, fuzz = 0.025;
  33.       point center = (0.5, 0.5, 0);  /* location of center of disk */
  34.       float radius = 0.35;           /* radius of disk */
  35.       d = distance(center,(s,t,0));
  36.       color layer_opac = 1 - smoothstep(radius - fuzz, radius, d);
  37.       Ci = blend(color1, color2, layer_opac);
  38.     } else     
  39.       Ci = color1;
  40.   }
  41.   else 
  42.     Ci = color1;
  43.   
  44.  
  45.   Oi = 1;
  46.   Ci = Ci * (Ka *ambient() + Kd * diffuse(Nf) + Ks* specular(Nf,-I,roughness));
  47. }
  48.  
  49.