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_veinedmarble.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.9 KB  |  75 lines

  1. /*
  2.  * veinedmarble.sl -- surface shader for a nice veined marble.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes solid marble texture with strong veins.  The "veincolor" parameter
  6.  *   controls the color of the veins.  The background color is given by the
  7.  *   surface color (Cs).
  8.  * 
  9.  * PARAMETERS:
  10.  *   Ka, Kd, Ks, roughness, specularcolor - same as plastic
  11.  *   veinfreq - controls fhe lowest frequency of the color veins
  12.  *   veinlevels - how many "levels" of vein tendrills it has
  13.  *   warpfreq - lowest frequency of the turbulent warping in the marble
  14.  *   warping - controls how much turbulent warping there will be
  15.  *   veincolor - the color of the veins
  16.  *   sharpness - controls how sharp or fuzzy the veins are (higher = sharper)
  17.  *
  18.  *
  19.  * AUTHOR: Larry Gritz, the George Washington University
  20.  *         email: gritz@seas.gwu.edu
  21.  *
  22.  * HISTORY:
  23.  *
  24.  * last modified  29 Jun 1994 by Larry Gritz
  25.  */
  26.  
  27. #include "k3d_noises.h"
  28. #include "k3d_rayserver.h"
  29. #include "k3d_material.h"
  30.  
  31.  
  32. surface k3d_veinedmarble(float Ka = .5;
  33.              float Kd = .8;
  34.              float Ks = .4;
  35.              float roughness = .075;
  36.              color specularcolor = 1;
  37.              float veinfreq = 1;
  38.              float veinlevels = 2;
  39.              float warpfreq = 1;
  40.              float warping = .5;
  41.              color veincolor = color(.6, .5, .1);
  42.              float sharpness = 8;
  43.   )
  44. {
  45.   color Ct;
  46.   point offset;
  47.   float i, turb, freq;
  48.   float turbsum;
  49.  
  50.   point PP = transform("shader", P);
  51.   float dPP = filterwidthp(PP);
  52.  
  53.   PP += 0.5 * vfBm(PP, dPP, 6, 2, 0.5);
  54.  
  55.   /* Now calculate the veining function for the lookup area */
  56.   turbsum = 0;
  57.   freq = 1;
  58.   PP *= veinfreq;
  59.   for(i = 0; i < veinlevels; i += 1)
  60.     {
  61.       turb = abs(filteredsnoise(PP * freq, dPP * freq));
  62.       turb = pow(smoothstep(0.8, 1, 1 - turb), sharpness) / freq;
  63.       turbsum += (1 - turbsum) * turb;
  64.       freq *= 3;
  65.       PP *= 3;
  66.     }
  67.  
  68.   Ct = mix(Cs, veincolor, turbsum);
  69.  
  70.   normal Nf = faceforward(normalize(N), I);
  71.   Ci = MaterialPlastic(Nf, Ct, Ka, Kd, Ks, roughness);
  72.   Oi = Os;
  73.   Ci *= Oi;
  74. }
  75.