home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libsurf / fog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.8 KB  |  79 lines

  1. /*
  2.  * fog.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * fog.c,v 4.1 1994/08/09 08:01:25 explorer Exp
  17.  *
  18.  * fog.c,v
  19.  * Revision 4.1  1994/08/09  08:01:25  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:13  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:40:14  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "atmosphere.h"
  30. #include "fog.h"
  31.  
  32. Fog *
  33. FogCreate(color, trans)
  34. Color *color, *trans;
  35. {
  36.     Fog *fog;
  37.     static void ComputeFog();
  38.  
  39.     fog = (Fog *)Malloc(sizeof(Fog));
  40.  
  41.     if (color == (Color *)NULL)
  42.         fog->color.r = fog->color.g = fog->color.b = 0.;
  43.     else
  44.         fog->color = *color;
  45.     if (trans == (Color *)NULL)
  46.         fog->trans.r = fog->trans.g = fog->trans.b = FAR_AWAY;
  47.     else {
  48.         fog->trans = *trans;
  49.     }
  50.     return fog;
  51. }
  52.  
  53. /*
  54.  * Add fog to the given color.
  55.  */
  56. void
  57. FogApply(fog, ray, pos, dist, color)
  58. Fog *fog;
  59. Ray *ray;
  60. Vector *pos;
  61. Float dist;
  62. Color *color;
  63. {
  64.     Float atten;
  65.     extern Float ExpAtten();
  66.  
  67.     atten = ExpAtten(dist, fog->trans.r);
  68.     if (fog->trans.r == fog->trans.g && fog->trans.r == fog->trans.b) {
  69.         ColorBlend(color, &fog->color, atten, 1. - atten);
  70.         return;
  71.     }
  72.     color->r = atten*color->r + (1. - atten) * fog->color.r;
  73.  
  74.     atten = ExpAtten(dist, fog->trans.g);
  75.     color->g = atten*color->g + (1. - atten) * fog->color.g;
  76.     atten = ExpAtten(dist, fog->trans.b);
  77.     color->b = atten*color->b + (1. - atten) * fog->color.b;
  78. }
  79.