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_hair.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  927 b   |  31 lines

  1. /** From RenderMan AppNote #19 */
  2.  
  3. surface k3d_hair(
  4.     float Ka = 1;
  5.     float Kd = .6;
  6.     float Ks = .35;
  7.     float roughness = .15;
  8.     color rootcolor = color (.109, .037, .007);
  9.     color tipcolor = color (.519, .325, .125);
  10.     color specularcolor = (color(1) + tipcolor) / 2;
  11.     )
  12. {
  13.     vector T = normalize (dPdv); /* tangent along length of hair */
  14.     vector V = -normalize(I);    /* V is the view vector */
  15.     color Cspec = 0, Cdiff = 0;  /* collect specular & diffuse light */
  16.     float cosang;
  17.  
  18.     /* Loop over lights, catch highlights as if this was a thin cylinder */
  19.     illuminance (P)
  20.         {
  21.             cosang = cos (abs (acos (T.normalize(L)) - acos (-T.V)));
  22.             Cspec += Cl * v * pow (cosang, 1/roughness);
  23.             Cdiff += Cl * v;
  24.  
  25.             /* We multipled by v to make it darker at the roots.  This assumes v=0 at the root, v=1 at the tip.  */
  26.         }
  27.  
  28.     Oi = Os;
  29.     Ci = Oi * (mix(rootcolor, tipcolor, v) * (Ka*ambient() + Kd * Cdiff) + (Ks * Cspec * specularcolor));
  30. }
  31.