/*-----------------------------------------------------------------------
 * rsmetal - a surface shader producing a highly specular finish
 *	     by randomly perturbing the specular reflections and
 *	     whose color is determined from Cs.
 *
 * Ka, Ks, Kr, roughness - the usual meaning
 *-----------------------------------------------------------------------*/

surface
rsmetal (float Ka=1, float Ks=1, float Kr = 0.6, float roughness=.1)
{
    normal Nf;
    vector V, D;
    color Cr;
    float w;

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

	/* Yes, we really DO want this noise in world space */
    w = 0.6 * noise(D * 2.5) +
        0.2 * noise(D * 5) +
        0.1 * noise(D * 10) +
        0.05 * noise(D * 20);
    w = w * w * w;
    Cr = Kr * w;

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

