home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / ddj1188.lzh / UPSTILL.ASC < prev   
Text File  |  1988-10-21  |  4KB  |  153 lines

  1. _PHOTOREALISM AND COMPUTER GRAPHICS_
  2. by
  3. Steve Upstill
  4.  
  5. [EXAMPLE 1]
  6.  
  7. surface 
  8. marble( float Kd=.5, Ka=.1;
  9.         color veincolor=0)
  10. {
  11.      float khi ;
  12.      point fnormal ;
  13.      color surfcolor ;
  14.      point freq = 4 * P;
  15.      float turbulence = 0;
  16.      float amplitude = 1, octave;
  17.  
  18.      /* Make sure the eye-vector points the right way */
  19.     fnormal = faceforward( normalize(N), I ) ;
  20.  
  21.      /* Accumulate a 3-dimensional noise function over 6 octaves,
  22.         weighting each by 1/f. */
  23.      for(octave = 0; octave < 6; octave = octave + 1 ) {
  24.           turbulence = turbulence + 
  25.                amplitude * abs(.5 - noise(freq));
  26.           amplitude = amplitude * .5;
  27.           freq = freq * 2;
  28.      }
  29.  
  30.     turbulence = 0.5 + 0.5 * sin(6*(xcomp(P)+turbulence)) ;
  31.     /* sharpen peaks */
  32.     turbulence = turbulence * turbulence * turbulence; 
  33.  
  34.     /* map discontinuously to vein colors */
  35.     khi = clamp((turbulence-0.5)*4, 0, 1);
  36.  
  37.     surfcolor = (1-khi)*Cs + khi*veincolor;
  38.     Ci = surfcolor*(Ka*ambient() + Kd*diffuse(N));
  39. }
  40.  
  41.  
  42.  
  43. [EXAMPLE 2]
  44.  
  45. light 
  46. windowlight( 
  47.      point     from =     point (3, 1, -1), /* Center of the window */
  48.                to =       point (0,0,0);
  49.      float     intensity=1, 
  50.                order = 2,      /* (# of panes up and down)/2   */
  51.                fuzz = .02,     /* blurred region around panes  */
  52.                framewid = .1,  /* width of a pane frame member */
  53.                panewid = .5;   /* width of the glass in a pane */
  54.      color     lightcolor =     color (1,.9,.6),
  55.                 darkcolor =     color (.05,.2,.1); 
  56. )
  57. {
  58.      float halfframeplus, halfframeminus;
  59.      float windowwid;
  60.      point wfrom, wto;
  61.      point wL, wP;
  62.      float shade, yabs, zabs, ymod, zmod;
  63.  
  64.      /* where pane-to-frame transition begins */
  65.      halfframeplus = framewid/2+fuzz; 
  66.      halfframeminus = framewid/2-fuzz;
  67.      windowwid = framewid+panewid;
  68.  
  69.      /* Move window center, sunlight vector back to world space */
  70.      wfrom = transform( "world", from ); 
  71.      wto = transform( "world", to );
  72.      wL = wto - wfrom; 
  73.  
  74.      wP = transform( "world", P );
  75.      /* Project surface position onto x=xcomp(wfrom) plane */
  76.      wL *= (xcomp(wfrom)-xcomp(wP))/xcomp(wL);
  77.      wP = wP + wL - wfrom;
  78.  
  79.      /* absolute distance from window center */
  80.      yabs = abs(ycomp(wP)); 
  81.      zabs = abs(zcomp(wP));
  82.      if( max(yabs, zabs)>(windowwid*order)) { /* Outside window? */
  83.          shade = 0;
  84.      } else {
  85.           /* Modulus reduces insideness to a single pane */
  86.          ymod = mod(yabs,windowwid);
  87.          zmod = mod(zabs,windowwid);
  88.          shade = 
  89.             smoothstep(halfframeminus, halfframeplus, ymod)*
  90.             smoothstep(halfframeminus, halfframeplus, windowwid-ymod)*
  91.             smoothstep(halfframeminus, halfframeplus, zmod)*
  92.             smoothstep(halfframeminus, halfframeplus, windowwid-zmod);
  93.      }
  94.  
  95.     L = to - from; /* always the same (needed for surface shading) */
  96.     Cl = mix(darkcolor, lightcolor, shade);
  97. }
  98.  
  99.  
  100.  
  101. [EXAMPLE 3]
  102.  
  103.  
  104. displacement
  105. threads ( float freq = 5.0, 
  106.                 amplitude = 0.1, 
  107.                 phase = 0.0, 
  108.                 offset = 0.0;)
  109. {
  110.     point nDel;
  111.     float scale;
  112.  
  113.      /* surface displacement occurs along nDel */
  114.     nDel = normalize(N); 
  115.  
  116.      /* The amount of displacement is given by a sinusoid along the
  117.          length of the cylinder, with the place around the cylinder
  118.          providing an additional phase factor for spiral threads */
  119.     scale = (sin( PI*2*(v*freq + u + phase))+offset) * amplitude;
  120.  
  121.     if( v > 0.95) /* Damp the oscillation to 0 at the ends */
  122.         scale = scale * (1.0-v) / .05;
  123.     else if( v < 0.05 )
  124.         scale = scale * v / .05;
  125.  
  126.     nDel = nDel * scale;
  127.     P = P + nDel;
  128.     N = calculatenormal(P);
  129. }
  130.  
  131.  
  132. [EXAMPLE 4]
  133.  
  134. surface
  135. filament ( float freq = 5.0, phase = 0.0, width = 0.3; 
  136.            color filcolor = color (1, .84, .76); )
  137. {
  138.     float distance; /* Distance from the spiral */
  139.  
  140.     distance = mod((t*freq + s + phase), 1.0);
  141.     if(distance < width) {
  142.         /* Inside the filament */
  143.         Ci = filcolor;
  144.         Oi = 1.0;     /* Make it opaque */
  145.     } else {
  146.         Oi = 0.0;  /* Make it transparent */
  147.      }
  148. }
  149.  
  150.  
  151.  
  152.  
  153.