/*---------------------------------------------------------------------------
 * cloth - displacement shader for a perpendicular weave pattern.
 *	Aliases pretty fiercely, but so does real cloth.
 *
 * freq - "frequency" of the weave
 * depth - displacement depth (displacement goes from -depth to +depth)
 *-------------------------------------------------------------------------*/
displacement
cloth(float freq=500, float depth=0.02, float s = u, float t = v)
{
    float d;
    normal sN;
    point PP;

    d = noise(freq*s) + noise(freq*t) - 1; /* from -1 to 1 */
    PP = transform("shader",P);
    sN = normalize(transform("shader",N));
    P = transform("shader","common",PP + sN*depth*d);
    N = calculatenormal(P);
}
