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_shifteddrtile.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.6 KB  |  94 lines

  1. /*
  2.  * TLShiftedD_RTile.sl -- generates a surface of alternating disks and rings
  3.  *
  4.  * DESCRIPTION:
  5.  *    Will generate alternating and shifted rows of disks and rings
  6.  * 
  7.  *
  8.  * PARAMETERS:
  9.  *    Ka, Kd, Ks - the usual
  10.  *  roughness -  Contols the specular reflection
  11.  *    fuzz -       Amount to blur edge
  12.  *    innerRadius - inner ring
  13.  *    outerRadius - outer ring
  14.  *    sfreq - # of tiles in s
  15.  *    tfreq - # of tiles in t 
  16.  *    cstate1 - foreground color
  17.  *    specularcolor - color of specular highlight
  18.  * 
  19.  * HINTS:
  20.  *    The center varible should really be placed in the parameter list 
  21.  *      (remember to set the right space)
  22.  *  Also, it would be better to set the width of the ring rather than
  23.  *      specifing the inner and outer ring.
  24.  *  Another thing that might be useful is to add a parameter to 
  25.  *      choose which row to do first.
  26.  * 
  27.  * AUTHOR: Tal Lancaster
  28.  *    tal@SpamSucks_cs.caltech.edu
  29.  *
  30.  * History:
  31.  *    Created: 8/12/95
  32.  */ 
  33.  #include "k3d_rmannotes.h"
  34.  #include "k3d_functions.h"
  35.  
  36.  
  37. surface
  38. k3d_shifteddrtile (
  39.     uniform float Ka = 1;
  40.     uniform float Kd = .5;
  41.     uniform float Ks = .5;
  42.     uniform float roughness = .1;
  43.     uniform float fuzz = .025;          /* amount to blur edge */
  44.     uniform float innerRadius = 0.3;    /* inner ring */
  45.     uniform float outerRadius = 0.45;   /* outer ring */
  46.     uniform float sfreq = 4.0;          /* # of tiles in s */
  47.     uniform float tfreq = 4.0;          /* # of tiles in t */
  48.     uniform color cstate1 = color(1, 0, 0);  /* foreground color */
  49.     uniform color specularcolor = 1;)
  50. {
  51.     point Nf;
  52.     uniform point center;      /* Center of disk */
  53.     color surfColor;   /* Color of surface */ 
  54.     float mix_opacity; /* How much to mix between the surfaces */
  55.     float ss, tt;      /* tiled s, t */
  56.     float row, col;    /* used to determine which tile we are in */
  57.     float d;           /* distance from center of current tile */
  58.     float wasOdd;      /* True if test was odd */
  59.     
  60.     Nf = faceforward (normalize(N),I);
  61.  
  62.     surfColor = Cs;
  63.     center = (0.5, 0.5, 0);  /* This should really be */
  64.                              /* put in the paramter list */
  65.  
  66.      row = whichtile (t, tfreq);
  67.     
  68.     if (isOdd(row) == 0) {
  69.         ss = mod (s * sfreq + 0.5, 1);
  70.         wasOdd = 0;
  71.     }
  72.     else {
  73.         ss = repeat (s, sfreq);
  74.         wasOdd = 1;
  75.     }
  76.     
  77.     tt = repeat (t, tfreq);
  78.     d = distance (center, (ss, tt, 0));
  79.  
  80.     if (wasOdd == 1)
  81.         /* Do ring */
  82.         mix_opacity = smoothPulse (innerRadius, outerRadius, fuzz, d);
  83.     else
  84.         /* Do disk */
  85.         mix_opacity = 1 - smoothstep (outerRadius-fuzz, outerRadius+fuzz, d);
  86.         
  87.     surfColor = mix (surfColor, cstate1, mix_opacity);
  88.     
  89.     
  90.     Oi = Os;
  91.     Ci = Os * (surfColor * (Ka*ambient() + Kd*diffuse(Nf)) +
  92.           specularcolor * Ks*specular(Nf,-normalize(I),roughness));
  93. }
  94.