/*	paintedplastic surface shader
 *
 * 	Pixie is:
 * 	(c) Copyright 1999-2003 Okan Arikan. All rights reserved.
 */

color specular( point N;vector V; float roughness) {
	color C = 0;
	float nonspec;
	point Nn,Ln;
	Nn = normalize( N );
	illuminance( P, Nn, PI/2 ) {
#if EITHER_WAY
	nonspec = 0;
	lightsource("__nonspecular", nonspec)
#else
	if (lightsource("__nonspecular", nonspec)==0)
		nonspec = 0;
#endif
        if (nonspec == 0) {
           vector R = -normalize(2*( N.L) * N - L);
           C += Cl * pow(max(R.normalize(-V),0.0),30);
           
        }
        }
	return C;
}

color diffuse( point N ) {
	color C = 0;
	point Nn, Ln;
	uniform float nondif;

	Nn = normalize( N );
	illuminance( P, Nn, PI/2 ) {
#if EITHER_WAY
		nondif = 0;
		lightsource("__nondiffuse", nondif);
#else
		if (lightsource("__nondiffuse", nondif)==0)
			nondif = 0;
#endif
		if (nondif == 0) {
			Ln = normalize( L );
			C += Cl * Ln.Nn;
		}
	}
	return C;
}

surface specpaintedplastic ( float Ka = 1, Kd = .5, Ks = .5, roughness = .1;
                         color specularcolor = 1;
                         string texturename = ""; ) {
    Ci = Cs;
    if (texturename != "")
	Ci *= color texture (texturename);

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

