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_star.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.3 KB  |  52 lines

  1. /* I took wave's lead and renamed star to DPStar.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /* 
  4.  * star.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. surface
  17. k3d_star(
  18.     uniform float Ka = 1;
  19.     uniform float Kd = 1;
  20.     uniform color starcolor = color (1.0000,0.5161,0.0000);
  21.     uniform float npoints = 5;
  22.     uniform float sctr = 0.5;
  23.     uniform float tctr = 0.5;
  24.      )
  25. {
  26.     point Nf = normalize(faceforward(N, I));
  27.     color Ct;
  28.     float ss, tt, angle, r, a, in_out;
  29.     uniform float rmin = 0.07, rmax = 0.2;
  30.     uniform float starangle = 2*PI/npoints;
  31.     uniform point p0 = rmax*(cos(0),sin(0),0);
  32.     uniform point p1 = rmin*
  33.         (cos(starangle/2),sin(starangle/2),0);
  34.     uniform point d0 = p1 - p0;
  35.     point d1;
  36.     
  37.     ss = s - sctr; tt = t - tctr;
  38.     angle = atan(ss, tt) + PI;
  39.     r = sqrt(ss*ss + tt*tt);
  40.     a = mod(angle, starangle)/starangle;
  41.     
  42.     if (a >= 0.5)
  43.         a = 1 - a;
  44.     d1 = r*(cos(a), sin(a),0) - p0;
  45.     in_out = step(0, zcomp(d0^d1));
  46.     Ct = mix(Cs, starcolor, in_out);
  47.     
  48.     /* diffuse ("matte") shading model */
  49.     Oi = Os;
  50.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  51. }
  52.