]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/oursun.cxx
Update the SoundSample api so we can request that a copy of the sample be
[simgear.git] / simgear / scene / sky / oursun.cxx
index fcb728d7844bc0748003dd744c9614af0520704c..10c6129a46f02db28b4a1bf1472a372b01fc8b0c 100644 (file)
@@ -49,6 +49,7 @@
 #include "sphere.hxx"
 #include "oursun.hxx"
 
+static double sun_exp2_punch_through;
 
 // Set up sun rendering call backs
 static int sgSunOrbPreDraw( ssgEntity *e ) {
@@ -74,9 +75,6 @@ static int sgSunOrbPostDraw( ssgEntity *e ) {
     glPopAttrib();
     // cout << "pop error = " << glGetError() << endl;
 
-    // glEnable( GL_DEPTH_TEST );
-    // glEnable( GL_FOG );
-
     return true;
 }
 
@@ -91,7 +89,8 @@ static int sgSunHaloPreDraw( ssgEntity *e ) {
     // cout << "push error = " << glGetError() << endl;
 
     glDisable( GL_DEPTH_TEST );
-//    glDisable( GL_FOG );
+    // glDisable( GL_FOG );
+    glFogf (GL_FOG_DENSITY, sun_exp2_punch_through);
     glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
 
     return true;
@@ -104,15 +103,14 @@ static int sgSunHaloPostDraw( ssgEntity *e ) {
     glPopAttrib();
     // cout << "pop error = " << glGetError() << endl;
 
-    // glEnable( GL_DEPTH_TEST );
-    // glEnable( GL_FOG );
-
     return true;
 }
 
 
 // Constructor
 SGSun::SGSun( void ) {
+    prev_sun_angle = -9999.0;
+    visibility = -9999.0;
 }
 
 
@@ -259,7 +257,7 @@ ssgBranch * SGSun::build( SGPath path, double sun_size ) {
                                    sgSunOrbPreDraw, sgSunOrbPostDraw );
 
     // force a repaint of the sun colors with arbitrary defaults
-    repaint( 0.0 );
+    repaint( 0.0, 1.0 );
 
     // build the halo
     // sun_texbuf = new GLubyte[64*64*3];
@@ -334,24 +332,36 @@ ssgBranch * SGSun::build( SGPath path, double sun_size ) {
 // 0 degrees = high noon
 // 90 degrees = sun rise/set
 // 180 degrees = darkest midnight
-bool SGSun::repaint( double sun_angle ) {
-    static float prev_sun_angle = 9999.0;
+bool SGSun::repaint( double sun_angle, double new_visibility ) {
+    if ( visibility != new_visibility ) {
+        visibility = new_visibility;
 
-    if (prev_sun_angle != sun_angle)
-    {
+        static double sqrt_m_log01 = sqrt( -log( 0.01 ) );
+        sun_exp2_punch_through = sqrt_m_log01 / (visibility * 15);
+    }
 
+    if (prev_sun_angle != sun_angle) {
         prev_sun_angle = sun_angle;
 
-        float sun_factor = 4*cos(sun_angle);
+        double nv = (new_visibility > 5000.0) ? new_visibility : 5000.0;
+        double vis_factor = 10000.0 / (nv - 5000.0);
+        if ( vis_factor < 0.25 ) {
+            vis_factor = 0.25;
+        } else if ( vis_factor > 1.0) {
+            vis_factor = 1.0;
+        }
+
+        float sun_factor = 4 * (cos(sun_angle) + cos(sun_angle)/2) * vis_factor;
 
         if (sun_factor > 1) sun_factor = 1.0;
         if (sun_factor < -1) sun_factor = -1.0;
-        sun_factor = sun_factor/2 + 0.5;
+        sun_factor = (sun_factor/2) + 0.5;
 
         sgVec4 color;
-        color[0] = pow(sun_factor, 0.25);
-        color[1] = pow(sun_factor, 0.50);
-        color[2] = pow(sun_factor, 4.0);
+        color[1] = sqrt(sun_factor);
+        color[0] = sqrt(color[1]);
+        color[2] = sun_factor * sun_factor;
+        color[2] *= color[2];
         color[3] = 1.0;
 
         gamma_correct_rgb( color );