]> git.mxchange.org Git - flightgear.git/blobdiff - src/Time/light.cxx
Clean-up cmake (linker) dependencies.
[flightgear.git] / src / Time / light.cxx
index 7c502d70ed455980dcd13f8d2e966a0ed9b92b80..d5e17686aa4782e2f1c23acea2af169d9fe7c5bd 100644 (file)
@@ -381,10 +381,17 @@ void FGLight::update_adj_fog_color () {
 
     float rf1 = fabs(fmod(hor_rotation, SGD_2PI) - SGD_PI) / SGD_PI;
     float rf2 = avf * pow(rf1*rf1, 1/sif) * 1.0639 * _saturation * _scattering;
+
+    // HACK: clamp rf2 to 1.0.
+    // Somehow, rf2 is huge at certain sun angles (around midnight), which results in
+    // rf3 being negative and hence negative fog colors and weird display issues...
+    // Something more fundamental may be wrong with the formulas here...
+    if (rf2>1.0) rf2 = 1.0;
+
     float rf3 = 1.0 - rf2;
 
     gamma = system_gamma * (0.9 - sif*avf);
-    _adj_fog_color = rf3 * _fog_color + rf2 * _sun_color;;
+    _adj_fog_color = rf3 * _fog_color + rf2 * _sun_color;
     gamma_correct_rgb( _adj_fog_color.data(), gamma);
 
     // make sure the colors have their original value before they are being
@@ -433,8 +440,8 @@ void FGLight::updateSunPos()
     SGVec3d nup = normalize(world_up);
     _sun_angle = acos( dot( nup, nsun ) );
 
-    double signnedPI = (_sun_angle < 0.0) ? -SGD_PI : SGD_PI;
-    _sun_angle = fmod(_sun_angle+signnedPI, SGD_2PI) - signnedPI;
+    double signedPI = (_sun_angle < 0.0) ? -SGD_PI : SGD_PI;
+    _sun_angle = fmod(_sun_angle+signedPI, SGD_2PI) - signedPI;
 
     SG_LOG( SG_EVENT, SG_DEBUG, "sun angle relative to current location = "
             << get_sun_angle() );