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_brick2.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.5 KB  |  59 lines

  1. /* I took wave's lead and renamed brick to DPBrick.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /* 
  4.  * brick.sl
  5.  *
  6.  * AUTHOR: Darwyn Peachy
  7.  *
  8.  * REFERENCES:
  9.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  10.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  11.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  12.  */
  13.  
  14. #include "k3d_proctext.h"
  15.  
  16. #define BRICKWIDTH      0.25
  17. #define BRICKHEIGHT     0.08
  18. #define MORTARTHICKNESS 0.01
  19.  
  20. #define BMWIDTH         (BRICKWIDTH+MORTARTHICKNESS)
  21. #define BMHEIGHT        (BRICKHEIGHT+MORTARTHICKNESS)
  22. #define MWF             (MORTARTHICKNESS*0.5/BMWIDTH)
  23. #define MHF             (MORTARTHICKNESS*0.5/BMHEIGHT)
  24.  
  25. surface
  26. k3d_brick2(
  27.     uniform float Ka = 1;
  28.     uniform float Kd = 1;
  29.     uniform color Cbrick = color (0.5, 0.15, 0.14);
  30.     uniform color Cmortar = color (0.5, 0.5, 0.5);
  31.      )
  32. {
  33.     color Ct;
  34.     point Nf;
  35.     float ss, tt, sbrick, tbrick, w, h;
  36.     float scoord = s;
  37.     float tcoord = t;
  38.  
  39.     Nf = normalize(faceforward(N, I));
  40.  
  41.     ss = scoord / BMWIDTH;
  42.     tt = tcoord / BMHEIGHT;
  43.  
  44.     if (mod(tt*0.5,1) > 0.5)
  45.         ss += 0.5;  /* shift alternate rows */
  46.     sbrick = floor(ss); /* which brick? */
  47.     tbrick = floor(tt); /* which brick? */
  48.     ss -= sbrick;
  49.     tt -= tbrick;
  50.     w = step(MWF,ss) - step(1-MWF,ss);
  51.     h = step(MHF,tt) - step(1-MHF,tt);
  52.  
  53.     Ct = mix(Cmortar, Cbrick, w*h);
  54.  
  55.     /* diffuse reflection model */
  56.     Oi = Os;
  57.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  58. }
  59.