home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / light / k3d_windowlight.sl < prev   
Encoding:
Text File  |  2008-01-23  |  2.6 KB  |  84 lines

  1. /****************************************************************************
  2.  * windowlight.sl - make a window light (with crossbars)
  3.  *
  4.  * Description::
  5.  *   Simulates light coming through a window.  The light doesn't
  6.  *   diverge or falloff.
  7.  *
  8.  * Parameters:
  9.  *   intensity - overall intensity scaling of the light
  10.  *   lightcolor - overall color filtering for the light
  11.  *   center - the spatial position of the center of the window
  12.  *   up, in - vectors which define the orientation of the window
  13.  *   from, to - the direction that the light falls
  14.  *   hpanes, vpanes - number of horizontal and vertical panes
  15.  *   panewidth, paneheight - width/height of the individual panes
  16.  *   fuzz - controls the fading out near the edges
  17.  *   framewidth, frameheight - how thick are the window frame "bars",
  18.  *               as percentage of panewidth/paneheight
  19.  *
  20.  * Author:  Larry Gritz, with inspiration from [Upstill]
  21.  *
  22.  * $Revision: 1.1 $    $Date: 2006/02/25 20:11:54 $
  23.  *
  24.  ****************************************************************************/
  25.  
  26. #include "k3d_patterns.h"
  27.  
  28. light k3d_windowlight(float intensity = 1;
  29.               color lightcolor = color(1, 0.9, 0.6);
  30.               color darkcolor = color(.05, 0.15, 0.1);
  31.               point from = point "shader"(0, 0, 0);
  32.               point to = point "shader"(0, 1, 0);
  33.               point center = point "shader"(0, 0, 0);
  34.               vector up = vector "shader"(0, 0, 1);
  35.               vector in = vector "shader"(0, 1, 0);
  36.               float hpanes = 2, vpanes = 3;
  37.               float panewidth = 6, paneheight = 6;
  38.               float framewidth = .1, frameheight = .1;
  39.               float fuzz = 0.25;
  40.   )
  41. {
  42.   uniform vector inv, right, upv;
  43.   uniform vector path;
  44.   float offset, modulus, yfract, xfract;
  45.   float d;
  46.   point PL;            /* point on the light */
  47.  
  48.   path = normalize(from - to);
  49.   inv = normalize(in);
  50.   right = (up) ^ inv;
  51.   upv = normalize(inv ^ right);
  52.   right = upv ^ inv;
  53.  
  54.   /* d is the depth "into" the room perpendicular to the pane plane */
  55.   d = inv.(Ps - center);
  56.   PL = Ps - path * (d / (path.inv));
  57.  
  58.   illuminate(PL, -path, .01)
  59.   {
  60.     offset = (PL - center).upv + paneheight * (vpanes / 2);
  61.     if(offset > 0 && (offset / paneheight) < vpanes)
  62.       {
  63.     modulus = mod(offset, paneheight);
  64.     yfract =
  65.       filteredpulse(frameheight / 2, paneheight - frameheight / 2,
  66.             modulus, fuzz);
  67.       }
  68.     else
  69.       yfract = 0;
  70.  
  71.     offset = (PL - center).right + panewidth * (hpanes / 2);
  72.     if(offset > 0 && (offset / panewidth) < hpanes)
  73.       {
  74.     modulus = mod(offset, panewidth);
  75.     xfract =
  76.       filteredpulse(framewidth / 2, panewidth - framewidth / 2, modulus,
  77.             fuzz);
  78.       }
  79.     else
  80.       xfract = 0;
  81.     Cl = intensity * mix(darkcolor, lightcolor, yfract * xfract);
  82.   }
  83. }
  84.