home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Stuff / 3D_Reality / Shaders / Shader_Source / SD_Checker_tx.sl < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.9 KB  |  71 lines

  1. /*************************************************************************
  2. *    Copyright (c) 1989-1992 Stone Design Corp.  All rights reserved. 
  3. *    programmer:    Bill Bumgarner
  4. *    File name:    SD_Checker_tx.sl
  5. *    Date:        Jul 21 1992 
  6. *    Purpose:    Map a texture to a surface.
  7. *
  8.     Variables:
  9.         s_frequency:    # of times to repeat textures
  10.                     in the s direction
  11.         t_frequency:    # of times to repeat textures 
  12.                     in the t direction
  13.         txmap:        full path to the texture map file
  14.         
  15.         s_percent1:         percentage of the surface area of each square
  16.         s_percent2:        of mixed textures (a 2x2 square) that is
  17.                     occupied by each texture.
  18.                 
  19.         do_depth_cues:    1 turns on lighting affects (see below)
  20.         
  21.         Ka:            percentage of ambient light used
  22.         Kd:            percentage of diffuse light used
  23.         Ks:            factor of effect for the specular highlight
  24.         roughness:        roughness factor for surface; used w/highlight
  25.         specularcolor:      color used for specular highlight        
  26. ***************************************************************************/
  27.  
  28. surface SD_Checker_tx(
  29.     float     s_frequency     = 1.,
  30.         t_frequency     = 1.;
  31.  
  32.     string    txmap1        = "",
  33.         txmap2        = "";
  34.         
  35.     float    s_percent1    = .5,
  36.         t_percent1    = .5;
  37.         
  38.     float   do_depth_cues    =  0;
  39.     
  40.     float     Ka        =  1,
  41.         Kd        = .5,
  42.         Ks        = .5,
  43.         roughness    = .1;
  44.     color    specularcolor    =  1;    
  45. )
  46. {
  47.     float ss = mod(s_frequency * s, 1)*2;
  48.     float tt = mod(t_frequency * t, 1)*2;
  49.     point Nf; 
  50.  
  51.  
  52.     if(    ((ss < (s_percent1*2)) && (tt<(t_percent1*2))) || 
  53.             ((ss > (s_percent1*2)) && (tt>(t_percent1*2)))   ){
  54.         if(txmap1 != "")
  55.         Ci = color texture(txmap1, mod(ss,1), mod(tt,1));
  56.         else
  57.         Ci = Cs;
  58.     } else {
  59.         if(txmap2 != "")
  60.         Ci = color texture(txmap2, mod(ss,1), mod(tt,1));
  61.         else
  62.         Ci = Cs;
  63.     }
  64.     
  65.     Oi = Os;
  66.     if(do_depth_cues != 0){
  67.         Nf= faceforward(N, I);
  68.         Ci=Os * (Ci * (Ka*ambient() + Kd*diffuse(Nf)) + 
  69.         specularcolor * Ks * specular(Nf,-I,roughness));
  70.     }
  71. }