/*---------------------------------------------------------------------------
 *	spatter - make surface look dark blue with white paint spatters,
 *	like on that camping cookware. (Or any base color with any color
 *	paint spatters).
 *
 *	Ka, Kd, Ks, roughness, specularcolor - the usual meaning
 *	specksize - size of the smallest paint specks
 *	sizes - number of different sizes of paint specks (each double
 *		the previous size)
 *	basecolor - the background color on which to spatter paint
 *	spattercolor - the color of the paint spatters
 *--------------------------------------------------------------------------*/
surface
spatter(float Ka = 1, float Kd = 0.5, float Ks = 0.7, float roughness = 0.2, float specksize = .01,
	float sizes = 5, color specularcolor = 1, color basecolor = color (.1,.1,0.5),
	color spattercolor = color (1,1,1))
{
	float speckle,size,scalefac,
		      threshold = 0.7;
	color paint;
	normal Nf;
	vector V;

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

    /* "OR" together various-sized noise spots. If any white, make paint white*/
	scalefac = 1/specksize;
	paint = basecolor;
	for (size=1; size<=sizes; size +=1) {
		speckle = noise(transform("shader",P)*scalefac);
		if (speckle > threshold) {
			paint = spattercolor;
			break;
		}
		scalefac /= 2;
	}

    /* get final color */
	C = opacity * (paint * (Ka * ambient() + Kd * diffuse(Nf)) +
		specularcolor * Ks * specular(Nf,V,roughness));
}
