]> git.mxchange.org Git - flightgear.git/commitdiff
#591: Fix sky flickering at certain sun/view angles
authorThorstenB <brehmt@gmail.com>
Wed, 7 Mar 2012 19:43:52 +0000 (20:43 +0100)
committerThorstenB <brehmt@gmail.com>
Wed, 7 Mar 2012 19:43:52 +0000 (20:43 +0100)
Commit 5f0066c resulted in an incorrect angle calculation. At certain view/sun
angles "hor_rotation" and "rf1" would skip from the minimum to the maximum
value).
Also, an offset angle of 90 degrees (PI/2) is added, which seems to align
the sky effect with the sun position. Calculation is probably still wrong,
but seems less wrong than before - and the flickering is gone...

src/Time/light.cxx

index d5e17686aa4782e2f1c23acea2af169d9fe7c5bd..c348fd4d56f93ef1b81b4ca52e98afd5c3eb5200 100644 (file)
@@ -349,8 +349,6 @@ void FGLight::update_adj_fog_color () {
     // direction to the sun
     //double vert_rotation = pitch + pitch_offset;
 
-    double hor_rotation = -_sun_rotation + SGD_PI - heading + heading_offset;
-
     // revert to unmodified values before using them.
     //
     SGSky* thesky = globals->get_renderer()->getSky();
@@ -379,15 +377,15 @@ void FGLight::update_adj_fog_color () {
     if (sif < 1e-4)
        sif = 1e-4;
 
-    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;
+    // determine horizontal angle between current view direction and sun
+    double hor_rotation = -_sun_rotation - SGD_PI_2 - heading + heading_offset;
+    if (hor_rotation < 0 )
+        hor_rotation = fmod(hor_rotation, SGD_2PI) + SGD_2PI;
+    else
+        hor_rotation = fmod(hor_rotation, SGD_2PI);
 
+    float rf1 = fabs((hor_rotation - SGD_PI) / SGD_PI); // 0.0 .. 1.0
+    float rf2 = avf * pow(rf1*rf1, 1/sif) * 1.0639 * _saturation * _scattering;
     float rf3 = 1.0 - rf2;
 
     gamma = system_gamma * (0.9 - sif*avf);