/* ctexmap.sl */

/*---------------------------------------------------------------------------- 
 * ctexmap - color texture-map surface shader *
 * Puts a color texture map onto a surface.  
 *
 * PARAMETERS:
 * texname - the name of the texture file
 * Ka, Kd, Ks, roughness, specularcolor - the usual meaning
 * scale - the usual meaning
 *---------------------------------------------------------------------------
 *
 * 
 * AUTHOR:  Nancy Kiang, adapted from bwtexmap.sl
 *
*/

surface
ctexmap(string texname = "";	
	float Ka=1, Kd=0.5, Ks=0.1, roughness=.25;	
	color specularcolor = 1;
	float scales = 1, scalet=1)
{	
	varying color ctx;
	
	normal Nf = faceforward( normalize(N), I);

	if (texname == "")
		ctx = 1;
	else
 		ctx = color texture(texname, (s/scales - 0.5), (t/scalet - 0.5));
	Oi = Os;
 	Ci = Os * (ctx * (Ka*ambient() + Kd*diffuse(Nf))
			+ Ks*specularcolor*specular(Nf,normalize(-I),roughness));
}