#include "/home/ee/cs184/lib/BMRT2.3.6/shaders/noises.h"



displacement
grassdp(float freq = 10;
	  float Km = 10;
	  float octaves = 3;
	  float trough = 0, peak = 1)
{
    point Pshad;       /* Point to be shaded, in shader space */
    normal NN;         /* Unit length surface normal */
    float fwidth;      /* Estimated change in P between image samples */
    float disp;        /* Amount to displace */

    /* Do texture calcs in "shader" space */
    Pshad = freq * transform ("shader", P);

    /* Estimate how much Pshad changes between adjacent iamge samples */
    fwidth = sqrt (area(Pshad));

    /* Compute some fractional Brownian motion */
    disp = filtered_fBm (Pshad, fwidth, 3, 2, 0.6);
    
    /* Threshold the fBm and scale it */
    disp = Km * smoothstep (trough, peak, disp);

    /* displace in shader space units */
    NN = normalize(N);
    P += NN * (disp / length (ntransform ("shader", NN)));
    N = normalize (calculatenormal(P));
}