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_ember.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.7 KB  |  76 lines

  1. /* Glowing ember shader ⌐2002 Graeme Nattress & NOITAMINANIMATION Inc.
  2.  *
  3.  * email: graeme@noitaminanimation.com
  4.  *
  5.  * It is designed for use with particle systems where the particle is scaled
  6.  * to represent it's life. The desired effect is that of glowing particles that
  7.  * dim and fade as they die.
  8.  *
  9.  * baseSize = the basic diameter of the particle sphere before scaling
  10.  *  
  11.  *    
  12.  */
  13.  
  14. surface
  15. k3d_ember (    float baseSize = 2;
  16.         float attenuation = 4;
  17.         float roughness = 0.99;
  18.        )
  19. {
  20.     point PP = transform ("world", P);
  21.     point QQ = transform ("world", point "object" (0, 0, 0));
  22.     
  23.     float size = distance (PP, QQ) / baseSize;
  24.     
  25.     //size now represents the size of the sphere particle normalised into 0,1.
  26.     
  27.     normal Nf;
  28.     vector V;
  29.     normal NN, NI;
  30.     
  31.     NN = normalize(N);
  32.     NI = normalize(I);
  33.     Nf = faceforward(NN,I);
  34.     V = vector -NI;
  35.     
  36.     float angle = NN . NI;
  37.     // angle for edge opacity falloff
  38.     
  39.     float spcol = pow (max (0, Nf.NI * -1), 1/roughness);
  40.     // basically, the standard specular function, but so that the highlight is
  41.     // always in the centre of the particle sphere.
  42.                             
  43.     Ci = color spline (spcol * size, 
  44.         color (0, 0, 0), color (0, 0, 0),
  45.         color (27, 0, 0),
  46.         color (54, 0, 0),
  47.         color (81, 0, 0),
  48.         color (109, 0, 0),
  49.         color (136, 0, 0),
  50.         color (166, 5, 0),
  51.         color (189, 30, 0),
  52.         color (211, 60, 0),
  53.         color (231, 91, 0),
  54.         color (238, 128, 0),
  55.         color (244, 162, 12),
  56.         color (248, 187, 58),
  57.         color (251, 209, 115),
  58.         color (254, 236, 210),
  59.         color (255, 241, 230),
  60.         color (255, 241, 230)) / 255;
  61.     // the colours for the fire effect from F. Kenton Musgrave's KMFlame.sl
  62.     
  63.     //only back face shade...
  64.     if (angle < 0) {
  65.     
  66.         angle = pow(angle, attenuation);
  67.         
  68.         Ci *= angle;
  69.         Oi = angle * size;
  70.     
  71.     } else {
  72.         Oi = 0;
  73.         Ci *= Oi;
  74.     }
  75. }
  76.