home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / atmosphere.c next >
Text File  |  1990-05-08  |  2KB  |  89 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.1.1 89/11/16 20:38:39 craig Exp Locker: craig $
  22.  *
  23.  * $Log:    atmosphere.c,v $
  24.  * Revision 3.0.1.1  89/11/16  20:38:39  craig
  25.  * patch1: Changes to accommodate atmosphere.h.
  26.  * 
  27.  * Revision 3.0  89/10/27  02:05:46  craig
  28.  * Baseline for first official release.
  29.  * 
  30.  */
  31. #include <stdio.h>
  32. #include <math.h>
  33. #include "typedefs.h"
  34. #include "constants.h"
  35. #include "funcdefs.h"
  36. #include "atmosphere.h"
  37.  
  38. Fog *GlobalFog;
  39. Mist *GlobalMist;
  40.  
  41. /*
  42.  * Add fog to the given color.
  43.  */
  44. ComputeFog(fog, dist, color)
  45. Fog *fog;
  46. double dist;
  47. Color *color;
  48. {
  49.     double atten;
  50.  
  51.     atten = LNHALF * dist * fog->trans;
  52.     if (atten < -10.)
  53.         atten = 0.;
  54.     else
  55.         atten = exp(atten);
  56.     blend_color(color, &fog->color, atten, 1. - atten);
  57. }
  58.  
  59. /*
  60.  * Add low-altitude mist to the given color.
  61.  */
  62. ComputeMist(mist, origin, hit, dist, color)
  63. Mist *mist;
  64. Vector *origin, *hit;
  65. double dist;
  66. Color *color;
  67. {
  68.     double deltaZ, d, atten;
  69.  
  70.     deltaZ = mist->scale * (hit->z - origin->z);
  71.     if (abs(deltaZ) > EPSILON)
  72.         d = (exp(-origin->z*mist->scale + mist->zero) -
  73.                 exp(-hit->z*mist->scale + mist->zero)) / deltaZ;
  74.     else
  75.         d = exp(-hit->z*mist->scale + mist->zero);
  76.     d *= LNHALF * dist;
  77.     atten =  d /  mist->trans.r;
  78.     atten = (atten < -10. ? (0.) : exp(atten));
  79.     color->r = atten*color->r + (1. - atten)*mist->color.r;
  80.  
  81.     atten =  d /  mist->trans.g;
  82.     atten = (atten < -10. ? (0.) : exp(atten));
  83.     color->g = atten*color->g + (1. - atten)*mist->color.g;
  84.  
  85.     atten =  d /  mist->trans.b;
  86.     atten = (atten < -10. ? (0.) : exp(atten));
  87.     color->b = atten*color->b + (1. - atten)*mist->color.b;
  88. }
  89.