home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / rayshade / part01 / src / atmosphere.c next >
Encoding:
C/C++ Source or Header  |  1990-03-21  |  2.2 KB  |  85 lines

  1. /*
  2.  * atmosphere.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: atmosphere.c,v 3.0 89/10/27 02:05:46 craig Exp $
  22.  *
  23.  * $Log:    atmosphere.c,v $
  24.  * Revision 3.0  89/10/27  02:05:46  craig
  25.  * Baseline for first official release.
  26.  * 
  27.  */
  28. #include <stdio.h>
  29. #include <math.h>
  30. #include "typedefs.h"
  31. #include "constants.h"
  32. #include "funcdefs.h"
  33.  
  34. Fog *GlobalFog;
  35. Mist *GlobalMist;
  36.  
  37. /*
  38.  * Add fog to the given color.
  39.  */
  40. ComputeFog(fog, dist, color)
  41. Fog *fog;
  42. double dist;
  43. Color *color;
  44. {
  45.     double atten;
  46.  
  47.     atten = LNHALF * dist * fog->trans;
  48.     if (atten < -10.)
  49.         atten = 0.;
  50.     else
  51.         atten = exp(atten);
  52.     blend_color(color, &fog->color, atten, 1. - atten);
  53. }
  54.  
  55. /*
  56.  * Add low-altitude mist to the given color.
  57.  */
  58. ComputeMist(mist, origin, hit, dist, color)
  59. Mist *mist;
  60. Vector *origin, *hit;
  61. double dist;
  62. Color *color;
  63. {
  64.     double deltaZ, d, atten;
  65.  
  66.     deltaZ = mist->scale * (hit->z - origin->z);
  67.     if (abs(deltaZ) > EPSILON)
  68.         d = (exp(-origin->z*mist->scale + mist->zero) -
  69.                 exp(-hit->z*mist->scale + mist->zero)) / deltaZ;
  70.     else
  71.         d = exp(-hit->z*mist->scale + mist->zero);
  72.     d *= LNHALF * dist;
  73.     atten =  d /  mist->trans.r;
  74.     atten = (atten < -10. ? (0.) : exp(atten));
  75.     color->r = atten*color->r + (1. - atten)*mist->color.r;
  76.  
  77.     atten =  d /  mist->trans.g;
  78.     atten = (atten < -10. ? (0.) : exp(atten));
  79.     color->g = atten*color->g + (1. - atten)*mist->color.g;
  80.  
  81.     atten =  d /  mist->trans.b;
  82.     atten = (atten < -10. ? (0.) : exp(atten));
  83.     color->b = atten*color->b + (1. - atten)*mist->color.b;
  84. }
  85.