home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / displacemnt / k3d_waterdisplacement.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  857 b   |  33 lines

  1. /*
  2.  *    P            surface position
  3.  *    N            surface geometric normal
  4.  *    s, t        surface texture coordinates
  5.  *    Ng            surface geometric normal
  6.  *    u,v            surface parameters
  7.  *    du, dv        change in u, v across the surface
  8.  *    dPdu,dPdv    change in position with u and v
  9.  *    I            direction of ray stricking a surface point (from the camera)
  10.  *    E            position of the camera
  11.  */
  12.  
  13. displacement k3d_waterdisplacement (float Km = 1.0; string bumpmap = "")
  14. {
  15.     float    hump;
  16.     point    norm;
  17.     
  18.     /* STEP 1 - Make a copy of the surface normal */
  19.     norm = normalize (N);
  20.     
  21.     /* STEP 2 - Calculate an appropriate value for the displacement */
  22.     if (bumpmap != "")
  23.         hump = texture(bumpmap, s, t);    
  24.     
  25.     /* STEP 3 - Calculate a new position of the surface point, "P" */
  26.     P = P - norm * hump * Km;
  27.     
  28.     /* STEP 4 - Recalculate the surface normal */
  29.     N = calculatenormal (P);
  30. }
  31.  
  32.  
  33.