home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / KMShaders / KMPuffyClouds.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.6 KB  |  80 lines

  1. /* modified by wave to KMPuffyClouds for name space protection... */
  2. /*
  3.  * puffyclouds.sl -- RenderMan compatible surface shader for puffy
  4.  *                   clouds.
  5.  *
  6.  * DESCRIPTION:
  7.  *    Makes nice looking cumulous clouds like you would see in the sky
  8.  *    on a bright sunny day.  Works as a basic thresholded fBm.  Since
  9.  *    this texture is generally used as a backdrop, it does not take
  10.  *    lighting into account.  If you wanted a lit surface that looked like
  11.  *    puffy clouds (like painted clouds on a wall), then it would be pretty
  12.  *    easy to add the lighting.
  13.  *
  14.  * PARAMETERS:
  15.  *    txtscale - overall scaling factor
  16.  *    skycolor, cloudcolor - the obvious meanings
  17.  *    octaves, omega, lambda - control the fractal appearance of the clouds
  18.  *    threshold - fBm sum below this level is just blue sky
  19.  *
  20.  * ANTIALIASING:
  21.  *    None, but should be easy to add antialiasing simply by adaptively
  22.  *    setting the "octaves" parameter based on distance from eye point.
  23.  *
  24.  * AUTHOR:
  25.  *    C language version by F. Kenton Musgrave
  26.  *    Translation to RenderMan Shading Language by Larry Gritz.
  27.  *
  28.  * REFERENCES:
  29.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  30.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  31.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  32.  *
  33.  * HISTORY:
  34.  *    ??? - original C language version by Ken Musgrave
  35.  *    Apr 94 - translation to Shading Language by L. Gritz
  36.  *
  37.  * this file last updated 18 Apr 1994
  38.  */
  39.  
  40.  
  41.  
  42. /* Use signed Perlin noise */
  43. #define snoise(x) ((2*noise(x))-1)
  44.  
  45.  
  46. surface
  47. KMPuffyClouds (float Ka = 0, Kd = 0;
  48.            float txtscale = 1;
  49.            color skycolor = color(.15, .15, .6);
  50.            color cloudcolor = color(1,1,1);
  51.            float octaves = 8, omega = 0.5, lambda = 2;
  52.            float threshold = 0;
  53.           )
  54. {
  55.   float value;
  56.   color Ct;      /* Color of the surface */
  57.   point PP;      /* Surface point in shader space */
  58.   float i, a, l, o;
  59.  
  60.   PP = txtscale * transform ("shader", P);
  61.  
  62.   /* Use fractional Brownian motion to compute a value for this point */
  63. /*  value = fBm (PP, omega, lambda, octaves); */
  64.   value = 0;
  65.   l = 1;  o = 1;  a = 0;
  66.   for (i = 0;  i < octaves;  i += 1) {
  67.       a += o * snoise (PP*l);
  68.       l *= 2;  o *= omega;
  69.     }
  70.   value = a;
  71.  
  72.   Ct = mix (skycolor, cloudcolor, smoothstep (threshold, 1, value));
  73.   
  74.   /* Shade like matte, but use color Ct */
  75.   Oi = 1;    /* Make it opaque */
  76.   Ci = Ct;   /* This makes the color disregard the lighting */
  77.   /* Uncomment the next line if you want the surface to actually be lit */
  78. /*  Ci = Ct * (Ka * ambient() + Kd * diffuse(faceforward(N,I))); */
  79. }
  80.