displacement.vfl

[index]

11th February 2009   1:14pm 22sec
/stuhome/vsfx419/vex/displacement.vfl


Vex_displacement



/*     Displacemnt shader that using noise to generate a bumpy
    surface. Source code by Renee Tam.
*/
  
#pragma help      "a template displacement shader"
#pragma hint     Km     float
#pragma label     Km     "Bump Height"
#pragma range    Km     -1 1
#pragma hint    s_center float
#pragma label    s_center "centerS"
#pragma hint    t_center float
#pragma label    t_center "centerT"
#pragma hint    freq float
#pragma label    freq "frequency"
  
displacement
cutrDisplace (float Km = 0.1;
                float s_center = 0.5;
                float t_center = 0.5;
                float freq = 2)
{
  
  
/* STEP 1 - make a copy of the surface normal one unit in length */
vector n = normalize(N);
  
/* STEP 2 - calculate an appropriate value for the displacement */
//point    pp = transform(spacename, P); 
  
float r = sqrt( pow(s-s_center, 2) + pow(t-t_center, 2) );
r = r + noise( s * t);
float hump = sin(r * 6.83 * freq) * 0.5;
  
/* STEP 3 - calculate the new position of the surface point */
/*            P based on the value of hump */
P = P - n * hump * Km;
  
/* STEP 4 - calculate the new orientation of the surface normal */
N = computenormal(P);
}