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_mysky.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.4 KB  |  80 lines

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