home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / surface / k3d_bluemarble.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.5 KB  |  62 lines

  1. /* I took wave's lead and renamed bluemarb to DPBlueMarble.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /* 
  4.  * bluemarb.sl
  5.  *
  6.  * AUTHOR: Darwyn Peachy
  7.  *
  8.  * REFERENCES:
  9.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  10.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  11.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  12.  */
  13.  
  14. #include "k3d_proctext.h"
  15.  
  16. #define PALE_BLUE        color (0.25, 0.25, 0.35)
  17. #define MEDIUM_BLUE      color (0.10, 0.10, 0.30)
  18. #define DARK_BLUE        color (0.05, 0.05, 0.26)
  19. #define DARKER_BLUE      color (0.03, 0.03, 0.20)
  20. #define NNOISE           4
  21.  
  22. color
  23. marble_color(float m)
  24. {
  25.     return color spline(
  26.         clamp(2*m + .75, 0, 1),
  27.         PALE_BLUE, PALE_BLUE,
  28.         MEDIUM_BLUE, MEDIUM_BLUE, MEDIUM_BLUE,
  29.         PALE_BLUE, PALE_BLUE,
  30.         DARK_BLUE, DARK_BLUE,
  31.         DARKER_BLUE, DARKER_BLUE,
  32.         PALE_BLUE, DARKER_BLUE);
  33. }
  34.  
  35. surface
  36. k3d_bluemarble(
  37.     uniform float Ka = 1;
  38.     uniform float Kd = 0.8;
  39.     uniform float Ks = 0.2;
  40.     uniform float texturescale = 2.5;
  41.     uniform float roughness = 0.1;
  42.      )
  43. {
  44.     color Ct;
  45.     point NN;
  46.     point PP;
  47.     float i, f, marble;
  48.  
  49.     NN = normalize(faceforward(N, I));
  50.     PP = transform("shader", P) * texturescale;
  51.  
  52.     marble = 0; f = 1;
  53.     for (i = 0; i < NNOISE; i += 1) {
  54.         marble += snoise(PP * f)/f;
  55.         f *= 2.17;
  56.     }
  57.     Ct = marble_color(marble);
  58.  
  59.     Ci = Os * (Ct * (Ka * ambient() + Kd * diffuse(NN))
  60.         + Ks * specular(NN, normalize(-I), roughness));
  61. }
  62.