home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 August / chip_08_2000.iso / aktualnosci / shareware / Rhinoceros / rh11eval_20000320.exe / %MAINDIR% / RIB / screen_aa.sl < prev    next >
Encoding:
Text File  |  2000-06-08  |  2.5 KB  |  79 lines

  1. /*
  2.  * screen_aa.sl -- RenderMan compatible shader for a metalic screen.
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes a surface that looks like a metal screen.  Strips of metal run
  6.  *   parallel to lines of s and t.  You can adjust the Ka, Kd, Ks, etc.
  7.  *   to change the material appearance.  This texture antialiases pretty
  8.  *   well, even with only one sample per pixel.
  9.  *
  10.  * PARAMETERS:
  11.  *   Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader
  12.  *   frequency - how many cycles of screen in st space
  13.  *   density - how much of each cycle is opaque?
  14.  *
  15.  * AUTHOR: written by Larry Gritz
  16.  *
  17.  * last modified  31 Jan 1994 by Larry Gritz
  18.  *
  19.  *
  20.  * The RenderMan (R) Interface Procedures and RIB Protocol are:
  21.  *     Copyright 1988, 1989, Pixar.  All rights reserved.
  22.  * RenderMan (R) is a registered trademark of Pixar.
  23.  */
  24.  
  25.  
  26.  
  27. #define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1))
  28. #define MINFILTERWIDTH 1.0e-7
  29.  
  30.  
  31.  
  32. surface
  33. screen_aa (float Ka = 1, Kd = 0.75, Ks = 0.4, roughness = 0.1;
  34.        color specularcolor = 1;
  35.        float density = 0.25, frequency = 20;)
  36. {
  37.   normal Nf;    /* Forward facing Normal vector */
  38.   vector IN;    /* normalized incident vector */
  39.   float d;      /* Density at the sample point */
  40.   float ss, tt; /* s,t, parameters in phase */
  41.   float swidth, twidth, GWF, w, h;
  42.  
  43.   /* Compute a forward facing normal */
  44.   IN = normalize (I);
  45.   Nf = faceforward (normalize(N), I);
  46.  
  47.   /* Determine how wide in s-t space one pixel projects to */
  48.   swidth = max (abs(Du(s)*du) + abs(Dv(s)*dv), MINFILTERWIDTH) * frequency;
  49.   twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH) * frequency;
  50.  
  51.   /* Figure out where in the pattern we are */
  52.   ss = mod (frequency * s, 1);
  53.   tt = mod (frequency * t, 1);
  54.  
  55.   /* Figure out where the strips are. Do some simple antialiasing. */
  56.   GWF = density*0.5;
  57.   if (swidth >= 1)
  58.       w = 1 - 2*GWF;
  59.   else w = clamp (boxstep(GWF-swidth,GWF,ss), max(1-GWF/swidth,0), 1)
  60.      - clamp (boxstep(1-GWF-swidth,1-GWF,ss), 0, 2*GWF/swidth);
  61.   if (twidth >= 1)
  62.       h = 1 - 2*GWF;
  63.   else h = clamp (boxstep(GWF-twidth,GWF,tt), max(1-GWF/twidth,0),1)
  64.      - clamp (boxstep(1-GWF-twidth,1-GWF,tt), 0, 2*GWF/twidth);
  65.   /* This would be the non-antialiased version:
  66.    *    w = step (GWF,ss) - step(1-GWF,ss);
  67.    *    h = step (GWF,tt) - step(1-GWF,tt);
  68.    */
  69.   d = 1 - w*h;
  70.  
  71.   Oi = d;
  72.   if (d > 0) {
  73.       Ci = Oi * ( Cs * (Ka*ambient() + Kd*diffuse(Nf)) +
  74.          specularcolor * Ks*specular(Nf,-IN,roughness));
  75.     }
  76.   else
  77.       Ci = 0;
  78. }
  79.