home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / rayce27s / bg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-02  |  1.4 KB  |  53 lines

  1. /*
  2.  * bg.c -- background texturing.
  3.  * 
  4.  * (c) 1993, 1994, Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
  5.  * 
  6.  * This program is free software; you can redistribute it and/or modify it
  7.  * under the terms of the GNU General Public License as published by the
  8.  * Free Software Foundation;
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  * 
  19.  * This file is based on work by George Kyriazis.
  20.  * 
  21.  * the background color can be changed to have any kind of background
  22.  * texturing. (hint hint)
  23.  */
  24.  
  25. #include "ray.h"
  26. #include "proto.h"
  27. #include "extern.h"
  28.  
  29. color
  30. bgcolor(struct ray *r)
  31. {
  32.     color           c;
  33.     double          factor;
  34.  
  35.  
  36.  
  37.     /* if it is above the appropriate axis just give a grey value */
  38.     /* if below give a gradually whiter color                     */
  39.     factor = vdot(bggradient, r->dir);
  40.  
  41.     if (factor >= -EPSILON)
  42.     c = background_color;
  43.     else {
  44.     c.r = background_color.r * (1 - 0.8 * factor);
  45.     c.g = background_color.g * (1 - 0.8 * factor);
  46.     c.b = background_color.b * (1 - 0.8 * factor);
  47.     }
  48.  
  49.     c = normcol(c);
  50.  
  51.     return c;
  52. }
  53.