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_checkerboard.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.3 KB  |  53 lines

  1. #include "k3d_patterns.h"
  2.  
  3. surface k3d_checkerboard(float Ka = 1.0;
  4.              float Kd = 1.0;
  5.              float Ks = 0.5;
  6.              float roughness = 0.1; color specularcolor = 1.0;
  7.              uniform float TileS = 6.0; uniform float TileT = 6.0;
  8.              color EvenColor = 0.0;)
  9. {
  10.   point Nf;
  11.   float tiles, tilet;
  12.   float filters, filtert, filterst;
  13.   float filterwidths, filterwidtht;
  14.   float mixamount;
  15.   color checkcolor;
  16.  
  17. /*
  18.     // Calculate our "filter zone" around the edges of each tile ...
  19.     filters = mod((s * TileS * 2.0) - 1.0, 2.0);
  20.     filtert = mod((t * TileT * 2.0) - 1.0, 2.0);
  21.  
  22.     filterwidths = SFILTERWIDTH * TileS;
  23.     filterwidtht = TFILTERWIDTH * TileT;
  24.  
  25.     filters = filteredpulse(1.0 - filterwidths, 1.0 + filterwidths, filters, filterwidths);
  26.     filtert = filteredpulse(1.0 - filterwidtht, 1.0 + filterwidtht, filtert, filterwidtht);
  27.  
  28.     filterst = filters + filtert;
  29. */
  30.  
  31.   // Calculate which tile we're in ...
  32.   tiles = step(1.0, mod(s * TileS, 2.0));
  33.   tilet = step(1.0, mod(t * TileT, 2.0));
  34.  
  35.   if(tiles == tilet)
  36.     {
  37.       mixamount = 0.0;
  38.     }
  39.   else
  40.     {
  41.       mixamount = 1.0;
  42.     }
  43.  
  44.   checkcolor = mix(EvenColor, Cs, mixamount);
  45.  
  46.   // Diffuse reflection model ...
  47.   Nf = normalize(faceforward(N, I));
  48.   Oi = Os;
  49.   Ci =
  50.     Os * (checkcolor * (Ka * ambient() + Kd * diffuse(Nf)) +
  51.       specularcolor * Ks * specular(Nf, -normalize(I), roughness));
  52. }
  53.