#include "sphere.hxx"
#include "oursun.hxx"
-// FIXME: This should not be needed, but at this time (08/15/2003)
-// certain NVidia drivers don't seem to implement
-// fgPushAttrib(FG_FOG_BIT) properly. The result is that
-// there is not fog when looking at the sun.
-#ifndef SG_PROPER_FOG_SUPPORT
-static float curFogDensity;
-#endif
-
+static double sun_exp2_punch_through;
// Set up sun rendering call backs
static int sgSunOrbPreDraw( ssgEntity *e ) {
glPopAttrib();
// cout << "pop error = " << glGetError() << endl;
- // glEnable( GL_DEPTH_TEST );
- // glEnable( GL_FOG );
-
return true;
}
ssgLeaf *f = (ssgLeaf *)e;
if ( f -> hasState () ) f->getState()->apply() ;
-#ifndef SG_PROPER_FOG_SUPPORT
- glGetFloatv( GL_FOG_DENSITY, &curFogDensity );
-#endif
-
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_FOG_BIT );
// cout << "push error = " << glGetError() << endl;
glPopAttrib();
// cout << "pop error = " << glGetError() << endl;
-#ifndef SG_PROPER_FOG_SUPPORT
- glFogf( GL_FOG_DENSITY, curFogDensity );
-#endif
-
- // glEnable( GL_DEPTH_TEST );
- // glEnable( GL_FOG );
-
return true;
}
// Constructor
SGSun::SGSun( void ) {
+ prev_sun_angle = -9999.0;
+ visibility = -9999.0;
}
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGSun::repaint( double sun_angle, double new_visibility ) {
- static float prev_sun_angle = 9999.0;
-
if ( visibility != new_visibility ) {
- static double sqrt_m_log01 = sqrt( -log( 0.01 ) );
visibility = new_visibility;
+
+ static double sqrt_m_log01 = sqrt( -log( 0.01 ) );
sun_exp2_punch_through = sqrt_m_log01 / (visibility * 15);
}
- if (prev_sun_angle != sun_angle)
- {
-
+ 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[1] = sqrt(sun_factor);