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_greenmarble.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.0 KB  |  79 lines

  1. /*
  2.  * greenmarble.sl -- RenderMan compatible shader for green veined marble.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes a marble-like surface using a turbulence function.
  6.  *   
  7.  * PARAMETERS:
  8.  *   Ka, Kd, Ks, roughness, specularcolor - work just like the plastic
  9.  *   txtscale - overall scaling for the texture
  10.  *   darkcolor, lightcolor - colors of the underlying substrate
  11.  *   veincolor - color of the bright veins
  12.  *   veinfreq - controls the frequency of the veining effects
  13.  *   sharpness - how sharp the veins appear
  14.  *
  15.  *
  16.  * AUTHOR: Larry Gritz, 1994
  17.  *
  18.  */
  19.  
  20. #include "k3d_noises.h"
  21. #include "k3d_rayserver.h"
  22. #include "k3d_material.h"
  23.  
  24.  
  25. surface k3d_greenmarble(float Ka = 0.1, Kd = 0.6, Ks = 0.4, roughness = 0.1;
  26.             color specularcolor = 1;
  27.             color darkcolor = color(0.01, 0.12, 0.004);
  28.             color lightcolor = color(0.06, 0.18, 0.02);
  29.             color veincolor = color(0.47, 0.57, 0.03);
  30.             float veinfreq = 1;
  31.             float sharpness = 25; float txtscale = 1;
  32.   )
  33. {
  34.   color Ct;
  35.   float freq;
  36.   float turbsum, turb, i;
  37.  
  38.   point PP = txtscale * transform("shader", P);
  39.   float dPP = filterwidthp(PP);
  40.  
  41.   /*
  42.    * First calculate the underlying color of the substrate
  43.    *    Use turbulence - use frequency clamping
  44.    */
  45.   turb = 0.5 * turbulence(PP, dPP, 5, 2, 0.5);
  46.   Ct = mix(darkcolor, lightcolor, smoothstep(0.1, .35, turb));
  47.  
  48.   /*
  49.    * Now we layer on the veins
  50.    */
  51.  
  52.   /* perturb the lookup */
  53.   PP += vector(35.2, -21.9, 6.25) + 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 < 3; 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 *= 2;
  65.     }
  66.   turbsum *=
  67.     smoothstep(-0.1, 0.05, snoise(2 * (PP + vector(-4.4, 8.34, 27.1))));
  68.  
  69.   Ct = mix(Ct, veincolor, turbsum);
  70.  
  71.   /*
  72.    * Shade like plastic
  73.    */
  74.   normal Nf = faceforward(normalize(N), I);
  75.   Ci = MaterialPlastic(Nf, Ct, Ka, Kd, Ks, roughness);
  76.   Oi = Os;
  77.   Ci *= Os;
  78. }
  79.