/* This shader takes a simple image and applies it as a grid pattern.
** It further multiplies the image color alternately with a light and dark color to 
** produce a checkered pattern.
**
**  Copyright 2004 Andrew Osiow
**
**  
*/

surface
paintedcheckerplastic( float Ks=.5, Kd=.5, Ka=1, roughness=.1, frequency = 4;
         color specularcolor=1, blackcolor=.5;
	 string texturename = ""; )
{
    normal Nf;
    vector V;
    color Ct, Cg;

    Nf = faceforward( normalize(N), I );
    V = -normalize(I);
    
    float smod = mod (s* frequency, 1),
	  tmod = mod (t* frequency, 1);

    if (texturename != "") {
	Ct = color texture(texturename);
    } else {
	Ct = 1.0;
    }
    
    if (smod < 0.5) {
    	if (tmod < 0.5)
    		Cg = Cs;
    	else
    		Cg = blackcolor;
    }
    else {
    	if (tmod < 0.5)
    		Cg = blackcolor;
    	else
    		Cg = Cs;
    }


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