/* Gordon Huang
   cs184-am
   Lab 7
   11/11/98

Polka-dot shader
Ka, Kd, Ks, specularcolor, roughness - standard meanings
dotcolor, backcolor - RGB values
spacing, size - Overall size and spacing of dots, size <= 1

*/ 

surface
polka(
   float Ka=1, Kd=.6, Ks=0.4, roughness=.2;
   float spacing=2, size=.7;
   color specularcolor=1, dotcolor=color(0.6,0,0.85), backcolor=color(.15,.71,.64)
)
{
   normal Nf;
   varying color paint;
   varying float ss,tt;
   uniform float RADIUS = size/2;
   point PP, centerP;

   Nf = faceforward (normalize(N),I);

   ss = s*10/spacing;
   tt = t*10/spacing;
   ss = mod(ss, spacing/2) - RADIUS;
   tt = mod(tt, spacing/2) - RADIUS;

   if (((ss*ss) + (tt*tt)) <= (RADIUS*RADIUS))
   {
     paint = dotcolor;
   } else
   {
     paint = backcolor;
   } 

   Oi = Os;
   Ci = Os * ( paint * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,-normalize(I),roughness));
}