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_wallpaper.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.1 KB  |  74 lines

  1. /* I took wave's lead and renamed wallpaper to DPWallpaper.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /* 
  4.  * wallpaper.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.  #include "k3d_noises.h"
  14.  
  15. #define NCELLS 10
  16. #define CELLSIZE (1/NCELLS)
  17.  
  18. surface
  19. k3d_wallpaper(
  20.     uniform float Ka = 1;
  21.     uniform float Kd = 1;
  22.     uniform color starcolor = color (1.0000,0.5161,0.0000);
  23.     uniform float npoints = 5;
  24.      )
  25. {
  26.     color Ct;
  27.     point Nf;
  28.     float ss, tt, angle, r, a, in_out;
  29.     float sctr, tctr, scell, tcell;
  30.     float scellctr, tcellctr;
  31.     float i, j;
  32.     uniform float rmin = 0.01, rmax = 0.03;
  33.     uniform float starangle = 2*PI/npoints;
  34.     uniform point p0 = rmax*(cos(0),sin(0),0);
  35.     uniform point p1 = rmin*
  36.         (cos(starangle/2),sin(starangle/2),0);
  37.     uniform point d0 = p1 - p0;
  38.     point d1;
  39.  
  40.     scellctr = floor(s*NCELLS);
  41.     tcellctr = floor(t*NCELLS);
  42.     in_out = 0;
  43.  
  44.     for (i = -1; i <= 1; i += 1) {
  45.         for (j = -1; j <= 1; j += 1) {
  46.         scell = scellctr + i;
  47.         tcell = tcellctr + j;
  48.         if (float noise(3*scell-9.5,7*tcell+7.5) < 0.55) {
  49.                 sctr = CELLSIZE * (scell + 0.5
  50.                      + 0.6 * snoisexy(scell+0.5, tcell+0.5));
  51.                 tctr = CELLSIZE * (tcell + 0.5
  52.                      + 0.6 * snoisexy(scell+3.5, tcell+8.5));
  53.                 ss = s - sctr;
  54.                 tt = t - tctr;
  55.             
  56.                 angle = atan(ss, tt) + PI;
  57.                 r = sqrt(ss*ss + tt*tt);
  58.                 a = mod(angle, starangle)/starangle;
  59.             
  60.                 if (a >= 0.5)
  61.                     a = 1 - a;
  62.                 d1 = r*(cos(a), sin(a),0) - p0;
  63.                 in_out += step(0, zcomp(d0^d1));
  64.             }
  65.         }
  66.     }
  67.     Ct = mix(Cs, starcolor, step(0.5,in_out));
  68.  
  69.     /* "matte" reflection model */
  70.     Nf = normalize(faceforward(N, I));
  71.     Oi = Os;
  72.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  73. }
  74.