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_flame.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.3 KB  |  82 lines

  1. /*
  2.  * flame.sl -- RenderMan compatible surface shader for a flame-like texture.
  3.  *
  4.  * DESCRIPTION:
  5.  *    Makes something that looks like fire.
  6.  *
  7.  * PARAMETERS:
  8.  *    distortion - 
  9.  *    chaosscale, chaosoffset, octaves - control the fBm
  10.  *    flameheight, flameamplitude - scaling factors
  11.  *
  12.  * ANTIALIASING:
  13.  *    None, but should be easy to add antialiasing simply by adaptively
  14.  *    setting the "octaves" parameter based on distance from eye point.
  15.  *
  16.  * AUTHOR:
  17.  *    C language version by F. Kenton Musgrave
  18.  *    Translation to RenderMan Shading Language by Larry Gritz.
  19.  *
  20.  * REFERENCES:
  21.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  22.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  23.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  24.  *
  25.  * HISTORY:
  26.  *    ??? - original C language version by Ken Musgrave
  27.  *    Apr 94 - translation to Shading Language by L. Gritz
  28.  *
  29.  * this file last updated 18 Apr 1994
  30.  */
  31.  
  32. #include "k3d_noises.h"
  33.  
  34. surface k3d_flame(float distortion = 0;
  35.           float chaosscale = 1; 
  36.           float chaosoffset = 0;
  37.           float octaves = 7; 
  38.           float flameoffset = 0.0;
  39.           float flameamplitude = 2.0; 
  40.           float phase = 0.0
  41.           )
  42. {
  43.   point PP, PQ;
  44.   float freq;
  45.   float chaos, i, cmap;
  46.  
  47.   PP = point(s, t, phase);
  48.   PQ = PP;
  49.   PQ *= point(1, 1, exp(-ycomp(PP)));
  50.   freq = 1;
  51.   chaos = 0;
  52.   for(i = 0; i < octaves; i += 1)
  53.     {
  54.       chaos += VLNoise(freq * PQ, distortion) / freq;
  55.       freq *= 2;
  56.     }
  57.  
  58.   chaos = abs(chaosscale * chaos + chaosoffset);
  59.   cmap = 0.85 * chaos + flameoffset + (flameamplitude * ycomp(PP));
  60.     color theflames = spline(cmap,     color(0, 0, 0), \
  61.                                                                   color(0, 0, 0), \
  62.                                                                   color(27, 0, 0), \
  63.                                                                   color(54, 0, 0), \
  64.                                                                   color(81, 0, 0), \
  65.                                                                   color(109, 0, 0), \
  66.                                                                   color(136, 0, 0), \
  67.                                                                   color(166, 5, 0), \
  68.                                                                   color(189, 30, 0), \
  69.                                                                     color(211, 60, 0), \
  70.                                                                   color(231, 91, 0), \
  71.                                                                   color(238, 128, 0), \
  72.                                                                   color(244, 162, 12), \
  73.                                                                   color(248, 187, 58), \
  74.                                                                   color(251, 209, 115), \
  75.                                                                   color(254, 236, 210), \
  76.                                                                   color(255, 241, 230), \
  77.                                                                     color(255, 241, 230));
  78.   Ci = Cs * theflames / 255;
  79.  
  80.   Oi = 0.001;
  81. }
  82.