color Environment ( string envname, vector R )
{
	int istexture;
	gettextureinfo (envname, "exists", istexture);
	if (istexture) {
      return environment (envname, R);
    } else {
         return trace (P, R, "traceset", envname);
    }
}

surface
shinymetal (float Ka=1, float Ks=1, float Kr = 1, float roughness=.1,
	    string texturename = "")
{
    normal Nf;
    vector V;
    vector D;
    color  Cr;

    Nf = faceforward(normalize(N), I) ;
    V = normalize(-I);
    D = reflect(I, Nf) ;
    D = transform ("world", D);

    if (texturename != "") {
	Cr = Kr * Environment(texturename, D);
    } else {
	Cr = 0.;
    }

    C *= opacity * ( Ka*ambient() + Ks*specular(Nf,V,roughness) + Cr);
}
