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_warningstripes.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.7 KB  |  62 lines

  1. // K-3D
  2. // Copyright (c) 1995-2004, Timothy M. Shead
  3. //
  4. // Contact: tshead@k-3d.com
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2 of the License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. // General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public
  17. // License along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20. /** \file
  21.         \author Tim Shead (tshead@k-3d.com)
  22. */
  23.  
  24.  #include "k3d_rmannotes.h"
  25. /// Filtering code courtesy of the Advanced RenderMan book ... where else?
  26.  
  27. #define MIN_FILTER_WIDTH 1.0e-6
  28. #define filter_width(x) max(abs(Du(x)*du) + abs(Dv(x)*dv), MIN_FILTER_WIDTH)
  29.  
  30. float filtered_pulse_train(float edge, period, x, dx)
  31. {
  32.     float w = dx / period;
  33.     float x0 = x/period - w/2;
  34.     float x1 = x0 + w;
  35.     float nedge = edge / period;
  36.     
  37.     float integral(float t)
  38.     {
  39.         extern float nedge;
  40.         return ((1 - nedge) * floor(t) + max(0, t-floor(t)-nedge));
  41.     }
  42.     
  43.     return (integral(x1) - integral(x0)) / w;
  44. }
  45.  
  46. surface k3d_warningstripes(
  47.     float Frequency = 8.0;
  48.     color StripeColor = color(0, 0, 0)
  49.     )
  50. {
  51.     float stripe_position = filtered_pulse_train(0.5 / Frequency, 1.0 / Frequency, u+v, filter_width(u+v));
  52.  
  53.     color Ct = mix(Cs, StripeColor, stripe_position);
  54.  
  55.     vector Nf = normalize(faceforward(N, I));
  56.     
  57.     Oi = Os;
  58.     Ci = (Os * Ct * (ambient() + diffuse(Nf)));
  59. }
  60.  
  61.  
  62.