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_venus.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.9 KB  |  96 lines

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