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

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