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_sdixon.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.1 KB  |  40 lines

  1. /* Copyrighted Pixar 1989 */
  2. /* From the RenderMan Companion p.384 */
  3. /* Listing 16.37  Pencil-labeling surface shader*/
  4.  
  5. /*
  6.  * sdixon(): Paint the body of a pencil.
  7.  */
  8. surface
  9. k3d_sdixon(
  10.     float    Ka        = 1.0, 
  11.         Kd        = 1.0, 
  12.         Ks        = 1.0,
  13.          roughness     = .25;
  14.     color    green         = color(0, .2, 0), 
  15.         yellow         = color(.56, .23, 0);
  16.     string    texturename    = "")
  17. {
  18.     point Nf = faceforward(normalize(N),I);
  19.     point V = normalize(-I);
  20.     float ink;
  21.     color cout;
  22.  
  23.     /* This shader uses a single-channel texture map to apply a 
  24.      *   metallic-green ink to a matte-yellow background. */
  25.  
  26.     /* Get the amount of ink from texture file. */
  27.     ink = texture(texturename, s, t);
  28.  
  29.      /* Use ink to mix yellow and green */
  30.     cout = mix(yellow, green, ink);                      
  31.  
  32.     /* Compute the output color. Notice that as ink goes from zero to
  33.        one, the diffuse component goes to zero and the specular 
  34.        component is increased. This has the effect of transitioning
  35.        from a matte surface to a metallic one as ink is added. */
  36.     Oi = Os;
  37.     Ci = Os * cout * ( Ka*ambient() + (1-ink)*Kd*diffuse(Nf) +
  38.                     ink*Ks*specular(Nf,V,roughness) ) ;
  39. }
  40.