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

  1. /*
  2.  * wood2.sl -- another surface shader for wood.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes wood solid texture.
  6.  * 
  7.  * PARAMETERS:
  8.  *   Ka, Kd, Ks, specular, roughness - work just like the plastic shader
  9.  *   txtscale - overall scaling factor for the texture
  10.  *   ringscale - scaling for the ring spacing
  11.  *   lightwood, darkwood - surface colors for the wood itself
  12.  *   grainy - relative graininess (0 = no fine grain)
  13.  *
  14.  * AUTHOR: written by Larry Gritz (lg@bmrt.org)
  15.  *
  16.  * $Revision: 1.1 $    $Date: 2006/02/25 20:11:54 $
  17.  */
  18.  
  19.  
  20.  
  21. surface k3d_wood2(float Ka = 1, Kd = .75, Ks = .4;
  22.           float roughness = .1;
  23.           color specularcolor = 1;
  24.           float ringscale = 15;
  25.           float txtscale = 1;
  26.           color lightwood = color(0.69, 0.44, 0.25);
  27.           color darkwood = color(0.35, 0.22, 0.08); float grainy = 1;)
  28. {
  29.   point PP, PQ;            /* shading space point to be computed */
  30.   normal Nf;            /* forward facing normal */
  31.   color Ct;            /* surface color of the wood */
  32.   float r, r2;
  33.   float my_t;
  34.  
  35.   /* Calculate in shader space */
  36.   PP = txtscale * transform("shader", P);
  37.  
  38.   my_t = zcomp(PP) / ringscale;
  39.   PQ = point(xcomp(PP) * 8, ycomp(PP) * 8, zcomp(PP));
  40.   my_t += noise(PQ) / 16;
  41.  
  42.   PQ = point(xcomp(PP), my_t, ycomp(PP) + 12.93);
  43.   r = ringscale * noise(PQ);
  44.   r -= floor(r);
  45.   r = 0.2 + 0.8 * smoothstep(0.2, 0.55, r) * (1 - smoothstep(0.75, 0.8, r));
  46.  
  47.   /* \/--  extra line added for fine grain */
  48.   PQ = point(xcomp(PP) * 128 + 5, zcomp(PP) * 8 - 3, ycomp(PP) * 128 + 1);
  49.   r2 = grainy * (1.3 - noise(PQ)) + (1 - grainy);
  50.  
  51.   Ct = mix(lightwood, darkwood, r * r2 * r2);
  52.  
  53.  
  54.   /*
  55.    * Use the plastic illumination model
  56.    */
  57.   Nf = faceforward(normalize(N), I);
  58.   Oi = Os;
  59.   Ci =
  60.     Os * (Ct * (Ka * ambient() + Kd * diffuse(Nf)) +
  61.       specularcolor * Ks * specular(Nf, -normalize(I), roughness));
  62. }
  63.