# include <plib/ssgaLensFlare.h>
#endif
+#include <simgear/screen/colors.hxx>
+
#include "sphere.hxx"
#include "oursun.hxx"
-
// Set up sun rendering call backs
static int sgSunOrbPreDraw( ssgEntity *e ) {
/* cout << endl << "Sun orb pre draw" << endl << "----------------"
// 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;
// Constructor
SGSun::SGSun( void ) {
+ prev_sun_angle = -9999.0;
+ visibility = -9999.0;
}
texSize = width * width;
if ( !sun_texbuf ) {
- cout << "ouch ..." << endl;
+ SG_LOG( SG_EVENT, SG_ALERT,
+ "Could not allocate memroy for the sun texture");
exit(-1); // Ugly!
}
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];
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
-bool SGSun::repaint( double sun_angle ) {
- if ( sun_angle * SGD_RADIANS_TO_DEGREES < 100 ) {
- // else sun is well below horizon (so no point in repainting it)
-
- // x_10 = sun_angle^10
- double x_10 = sun_angle * sun_angle * sun_angle * sun_angle * sun_angle
- * sun_angle * sun_angle * sun_angle * sun_angle * sun_angle;
-
- float ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
- if (ambient < 0.3) { ambient = 0.3; }
- if (ambient > 1.0) { ambient = 1.0; }
-
- sgVec4 color;
- sgSetVec4( color,
- (ambient * 6.0) - 1.0, // minimum value = 0.8
- (ambient * 11.0) - 3.0, // minimum value = 0.3
- (ambient * 12.0) - 3.6, // minimum value = 0.0
- 1.0 );
-
- // temp test, forces the color to always be white
- // sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
-
- if (color[0] > 1.0) color[0] = 1.0;
- if (color[1] > 1.0) color[1] = 1.0;
- if (color[2] > 1.0) color[2] = 1.0;
-
- // cout << "color = " << color[0] << " " << color[1] << " "
- // << color[2] << endl;
-
- float *ptr;
- ptr = cl->get( 0 );
- sgCopyVec4( ptr, color );
+bool SGSun::repaint( double sun_angle, double new_visibility ) {
+ if ( visibility != new_visibility ) {
+ 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) {
+ prev_sun_angle = sun_angle;
+
+ float sun_factor = 4*cos(sun_angle);
+
+ if (sun_factor > 1) sun_factor = 1.0;
+ if (sun_factor < -1) sun_factor = -1.0;
+ sun_factor = sun_factor/2 + 0.5;
+
+ sgVec4 color;
+ 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 );
+
+ // cout << "color = " << color[0] << " " << color[1] << " "
+ // << color[2] << endl;
+
+ float *ptr;
+ ptr = cl->get( 0 );
+ sgCopyVec4( ptr, color );
}
return true;