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_puffyclouds.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.6 KB  |  77 lines

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