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_venus2.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  3.0 KB  |  93 lines

  1. /* I renamed the shader to MBVenus.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /*
  4.  * venus.sl - surface for a very cloudy planet like Venus.
  5.  *
  6.  *
  7.  * DESCRIPTION:
  8.  *      When put on a sphere, sets the color to look like a densely
  9.  *   clouded planet, very much like the real Venus appears in UV.
  10.  *      The shader works by creating a fractal turbulence function over
  11.  *   the surface to simulate the clouds.  Strong Coriolis forces are
  12.  *   simulated to give the twisting of clouds that is typically seen
  13.  *   on Venus.
  14.  *
  15.  *
  16.  * PARAMETERS:
  17.  *    Ka, Kd - the usual meaning
  18.  *    offset, scale - control the linear scaling of the cloud value.
  19.  *    twist - controls the twisting of the clouds due to Coriolis forces.
  20.  *    omega - controls the fractal characteristics of the clouds
  21.  *    octaves - the number of octaves of noise to sum for the clouds.
  22.  *    radius - radius of planet
  23.  *
  24.  *
  25.  * AUTHOR: Ken Musgrave.
  26.  *    Conversion to Shading Language and minor modifications by Larry Gritz.
  27.  *    Planet radius param added by Mark Beckwith.
  28.  *
  29.  * REFERENCES:
  30.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  31.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  32.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  33.  *
  34.  *
  35.  * HISTORY:
  36.  *    ???? - Venus texture developed by F. Ken Musgrave.
  37.  *    Feb 1994 - Conversion to Shading Language by L. Gritz
  38.  *    Dec 1996 - Added radius of planet as a parameter by Mark Beckwith
  39.  *        (mark@SpamSucks_intrig.com)
  40.  */
  41.  
  42.  
  43. #include "k3d_constants.h"
  44. #include "k3d_noises.h"
  45.  
  46.  
  47. surface
  48. k3d_venus2 (float Ka = 1, Kd = 1;
  49.        float offset = 1;
  50.        float scale = 0.6;
  51.        float twist = 0.22;
  52.        float omega = 0.65;
  53.        float octaves = 8;
  54.        float radius = 1)
  55. {
  56.   point Ptexture;           /* the shade point in texture space */
  57.   point PtN;                /* normalized version of Ptexture */
  58.   point PP;                 /* Point after rotation by coriolis twist */
  59.   float rsq;                /* Used in calculation of twist */
  60.   float angle;              /* Twist angle */
  61.   float sine, cosine;       /* sin and cos of angle */
  62.   float l, o, a, i;         /* Loop control for fractal sum */
  63.   float value;              /* Fractal sum is stored here */
  64.  
  65.   /* Transform to texture coordinates and map to nit sphere */
  66.   Ptexture = transform ("shader", P) / radius;
  67.  
  68.   /* Calculate Coriolis twist, yielding point PP */
  69.   PtN = normalize (Ptexture);
  70.   rsq = xcomp(PtN)*xcomp(PtN) + ycomp(PtN)*ycomp(PtN);
  71.   angle = twist * TWOPI * rsq;
  72.   sine = sin (angle);
  73.   cosine = cos (angle);
  74.   PP = point (xcomp(Ptexture)*cosine - ycomp(Ptexture)*sine,
  75.           xcomp(Ptexture)*sine + ycomp(Ptexture)*cosine,
  76.           zcomp(Ptexture));
  77.  
  78.   /* Compute VLfBm */
  79.   l = 1;  o = 1;  a = 0;
  80.   for (i = 0;  i < octaves;  i += 1) {
  81.       a += o * snoise (PP * l);
  82.       l *= 2;
  83.       o *= omega;
  84.     }
  85.  
  86.   value = abs (offset + scale * a);
  87.  
  88.   /* Shade like matte, but with color scaled by cloud color */
  89.   Oi = 1;
  90.   Ci = Os * (value * Cs) * (Ka * ambient() +
  91.                 Kd * diffuse(faceforward(normalize(N),I)));
  92. }
  93.