/* lab7.sl	---------------------------------------------*/
/* Name:   Phuc Nguyen                                       */
/* Login:  cs184-dh                                          */
/* SID:    13547274                                          */
/* ----------------------------------------------------------*/

/* --------------------------------------------------------- */
/* This is a surface shader that creates a regular array of  */
/* filled circles.                                           */
/* Parameters:                                               */
/*   circleColor (RBG color) - Color of the circles          */
/*   bkgrdColor  (RBG color) - background color              */
/*   radius      (float)     - radius of the circles         */
/*   frequency   (float)     - indicates how many times the  */
/*                             circles repeated in a unit    */
/*                             interval.                     */
/*                             Spacing of the circles        */
/*   roughness   (float)     - to adjust the brighness       */ 
/* ----------------------------------------------------------*/


#define sqr(x) ((x) * (x))

surface
lab7( color circleColor = color (0.8,0.7,0.7),
            bkgrdColor = color (0.8490, 0.2745, 0.2667);
      float radius = 0.3,     
            frequency = 10,
            roughness = 0.6,
            Ka = 1,
            Kd = .5,
            Ks = .2 )

{
   float 
         ss = mod(s*frequency,1) - 0.5 ,  /* locations from center */
         tt = mod(t*frequency,1) - 0.5;

   point Nf =  faceforward(normalize(N),I);
   point V = normalize(-I);

   if ((sqr(ss) + sqr(tt)) <= sqr(radius))
        Ci = circleColor;
   else
        Ci = bkgrdColor; 

  Oi = Os;
  Ci = Oi * Ci * (Ka * ambient() + Ks * specular(Nf,V, roughness) +
                  Kd * diffuse(Nf));
}