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_shiftedmoontile.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.2 KB  |  80 lines

  1. /*
  2.  * TLShiftedMoonTile.sl -- shifted tile of cresent moons
  3.  *
  4.  * DESCRIPTION:
  5.  *    Tile of shifted  cresent moons (disks)
  6.  * 
  7.  * PARAMETERS:
  8.  *    Ka, Kd, Ks - the usual
  9.  *  roughness - Contols the specular reflection
  10.  *    fuzz -      Amount to blur edge
  11.  *    radius -    Radis of disk (moon)
  12.  *    sfreq - # of tiles in s
  13.  *    tfreq - # of tiles in t
  14.  *    eclipseCenter - Center of obscuring disk
  15.  *    cstate1 - Color of disk
  16.  *    specularcolor - color of specular highlight
  17.  *
  18.  * HINTS:
  19.  *    Really should move center to the paramter list so both centers 
  20.  *     can be controled.
  21.  *
  22.  * AUTHOR: Tal Lancaster
  23.  *    tal@SpamSucks_cs.caltech.edu
  24.  *
  25.  * History:
  26.  *    Created: 8/12/95
  27.  */ 
  28.  
  29. #include "k3d_rmannotes.h"
  30. #include "k3d_functions.h"
  31.  
  32. surface
  33. k3d_shiftedmoontile (
  34.     uniform float Ka = 1;
  35.     uniform float Kd = .5;
  36.     uniform float Ks = .5;
  37.     uniform float roughness = .1;
  38.     uniform float fuzz = .02;
  39.     uniform float radius = 0.45;
  40.     uniform float sfreq = 4.0;
  41.     uniform float tfreq = 4.0;
  42.     uniform point eclipseCenter = point "current" (0.6, 0.5, 0);
  43.     uniform color cstate1 = color(1, 0, 0);
  44.     uniform color specularcolor = 1;)
  45. {
  46.     point Nf;
  47.     uniform point center;            /* Center of disk */
  48.     color surfColor;         /* Color of surface */
  49.     float mix_opacity;       /* How much to mix between the surfaces */
  50.     float circle1, circle2;  /* True if in circle1, circle2 */
  51.     float ss, tt;            /* Tile coordinates */
  52.     float row, col;          /* Location in tiles */
  53.     float d, d2;             /* Point distance from circle1, circle2 */
  54.  
  55.     Nf = faceforward (normalize(N),I);
  56.     surfColor = Cs;
  57.     center = (0.5, 0.5, 0);  /* This should really be moved */
  58.                              /*  to the paramter list */
  59.  
  60.      row = whichtile (t, tfreq);
  61.     if (isOdd(row) == 0)
  62.         ss = mod (s * sfreq + 0.5, 1);
  63.     else
  64.         ss = repeat (s, sfreq);
  65.     
  66.     tt = repeat (t, tfreq);
  67.     
  68.     d = distance (center, (ss, tt, 0));
  69.     d2 = distance (eclipseCenter, (ss, tt, 0));
  70.  
  71.     circle1 = 1 - smoothstep (radius - fuzz, radius + fuzz, d);
  72.     circle2 = 1 - smoothstep (radius - fuzz, radius + fuzz, d2);
  73.     mix_opacity = difference (circle1, circle2);
  74.     surfColor = mix (surfColor, cstate1, mix_opacity);
  75.     
  76.     Oi = Os;
  77.     Ci = Os * (surfColor * (Ka*ambient() + Kd*diffuse(Nf)) +
  78.           specularcolor * Ks*specular(Nf,-normalize(I),roughness));
  79. }
  80.