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_spacecloud.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.1 KB  |  92 lines

  1. /*
  2.  * TLSpaceCloud.sl - perform turbulence function to add more dimension to
  3.  *    texture-map and try to make it not so obvious that it is a texture-map.
  4.  *
  5.  *
  6.  * DESCRIPTION:
  7.  *   Uses a pulse function to tapper off the edges of the texture
  8.  *
  9.  * PARAMETERS:
  10.  *   txtFile -- texture map
  11.  *   startPulse -- start of pulse function.
  12.  *   endPulse -- end of pulse function
  13.  *   fuzz -- amount to blur the edges of the pulse
  14.  *   minAdjust -- amount that can be subtracted from value
  15.  *   maxAdjust -- amount that can be added to the value
  16.  *   maxOpacity -- maximin opacity for the surface
  17.  *
  18.  * HINTS:
  19.  *  Only tested on rectanglar patch.
  20.  *
  21.  * AUTHOR: Tal Lancaster
  22.  *
  23.  *
  24.  * HISTORY:
  25.  *  Created: 6/1/95
  26.  *  
  27.  *  tal 3/2/97  -- Cleaned up code, removed many constants, added comments
  28.  *  tal 2/23/97 -- Originally tried using fBm to create turbulence.  But
  29.  *      I was never happy with the results.  So now am just using noise over
  30.  *      u,v. 
  31.  */
  32. #include "k3d_noises.h"
  33. #include "k3d_functions.h"
  34.  
  35. #define  MINFREQ 1.1
  36. #define MAXFREQ 6
  37.  
  38.  
  39.  
  40.  
  41. surface k3d_spacecloud(
  42.   string txtFile = "";
  43.   float startPulse = .2; /* .1 .2 .3 .01 */
  44.   float endPulse = .9; /* .9 .8 .7 .8 */
  45.   float afuzz = .1;
  46.   float bfuzz = .2;
  47.   float minAdjust = -.4;
  48.   float maxAdjust = .4;
  49.   float maxOpacity = .4;
  50. )
  51. {
  52.   float value = 0;
  53.   float f;
  54.   color Ct;
  55.   point PP;
  56.   float freq, i, size;
  57.   float adjust;
  58.   float ss, tt;
  59.   
  60.  
  61.   if (txtFile != "")
  62.     Ct = color texture (txtFile, s, 1-t);
  63.   else
  64.     Ct = color (.3, .3, .3);
  65.  
  66.     PP = transform ("object", P);
  67.   /* fractalsum */
  68.   for (f = MINFREQ; f < MAXFREQ; f += 1)
  69.     value += abs(snoise (PP * f))/f;
  70.  
  71. #if 0
  72. #define  MINFREQ 1.1
  73. #define MAXFREQ 6
  74.     /* Old way */
  75.  
  76.     fBm (P, noiseScale, octaves, PP, freq, i, size, adjust);
  77.     /*printf ("%.3f %.3f: adjust %.3f\n", s, t, adjust);*/
  78.     
  79. #else
  80.     adjust = adjustNoise (u, v, minAdjust, maxAdjust);
  81.     ss = s + adjust;
  82.     tt = t + adjust;
  83.     /* printf ("%.3f %.3f: %.3f %.3f\n", s, t, ss-s, tt-t); */
  84.     
  85. #endif
  86.     Oi = value * smoothPulse2Fuzz (startPulse, endPulse, afuzz, afuzz, ss) * 
  87.         smoothPulse2Fuzz (startPulse, endPulse, bfuzz, afuzz, tt);
  88.  
  89.     Oi *= maxOpacity;
  90.     Ci = Ct * Oi * 1.75  /* saturate colors */;
  91. }
  92.