From 94c22fec4668b259e83038f6ba1f098df353c73e Mon Sep 17 00:00:00 2001 From: ehofman Date: Wed, 21 May 2003 17:17:47 +0000 Subject: [PATCH] Updates for a better sunrise/sunset effect --- simgear/scene/sky/dome.cxx | 10 ++++++-- simgear/scene/sky/oursun.cxx | 46 +++++++++++++++++++++++++++++------- simgear/screen/colors.hxx | 23 +++++++++++++++++- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/simgear/scene/sky/dome.cxx b/simgear/scene/sky/dome.cxx index 17fc03f4..0824a322 100644 --- a/simgear/scene/sky/dome.cxx +++ b/simgear/scene/sky/dome.cxx @@ -281,13 +281,19 @@ ssgBranch * SGSkyDome::build( double hscale, double vscale ) { bool SGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle, double vis ) { - double diff; + double diff, prev_sun_angle = 999.0; sgVec3 outer_param, outer_amt, outer_diff; sgVec3 middle_param, middle_amt, middle_diff; int i, j; + if (prev_sun_angle == sun_angle) + return true; + + prev_sun_angle = sun_angle; + // Check for sunrise/sunset condition - if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) { + if (sun_angle > 80.0) // && (sun_angle < 100.0) ) + { // 0.0 - 0.4 sgSetVec3( outer_param, (10.0 - fabs(90.0 - sun_angle)) / 20.0, diff --git a/simgear/scene/sky/oursun.cxx b/simgear/scene/sky/oursun.cxx index f94d0af4..ee757386 100644 --- a/simgear/scene/sky/oursun.cxx +++ b/simgear/scene/sky/oursun.cxx @@ -44,6 +44,8 @@ # include #endif +#include + #include "sphere.hxx" #include "oursun.hxx" @@ -333,8 +335,14 @@ ssgBranch * SGSun::build( SGPath path, double sun_size ) { // 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) + static float prev_sun_angle = 9999.0; + + // else sun is well below horizon (so no point in repainting it) +#if 0 + if ( (sun_angle * SGD_RADIANS_TO_DEGREES < 100 ) + && (prev_sun_angle != sun_angle)) + { + prev_sun_angle = sun_angle; // x_10 = sun_angle^10 double x_10 = sun_angle * sun_angle * sun_angle * sun_angle * sun_angle @@ -347,7 +355,7 @@ bool SGSun::repaint( double sun_angle ) { sgVec4 color; sgSetVec4( color, (ambient * 6.0) - 1.0, // minimum value = 0.8 - (ambient * 11.0) - 2.8, // minimum value = 0.5 + (ambient * 11.0) - 2.7, // minimum value = 0.6 (ambient * 12.0) - 3.6, // minimum value = 0.0 1.0 ); @@ -358,12 +366,34 @@ bool SGSun::repaint( double sun_angle ) { 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; +#else + + 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[0] = pow(sun_factor, 0.25); + color[1] = pow(sun_factor, 0.50); + color[2] = pow(sun_factor, 4.0); + color[3] = 1.0; + +#endif + gamma_correct_rgb( color ); + + // cout << "color = " << color[0] << " " << color[1] << " " + // << color[2] << endl; - float *ptr; - ptr = cl->get( 0 ); - sgCopyVec4( ptr, color ); + float *ptr; + ptr = cl->get( 0 ); + sgCopyVec4( ptr, color ); } return true; diff --git a/simgear/screen/colors.hxx b/simgear/screen/colors.hxx index 13c6ef3f..19759707 100644 --- a/simgear/screen/colors.hxx +++ b/simgear/screen/colors.hxx @@ -38,7 +38,7 @@ const float system_gamma = 2.5; // simple architecture independant gamma correction function. -inline void gamma_correct(float *color, +inline void gamma_correct_rgb(float *color, float reff = 2.5, float system = system_gamma) { color[0] = pow(color[0], reff/system); @@ -46,5 +46,26 @@ inline void gamma_correct(float *color, color[2] = pow(color[2], reff/system); }; +inline void gamma_correct_c(float *color, + float reff = 2.5, float system = system_gamma) +{ + *color = pow(*color, reff/system); +}; + +inline void gamma_restore_rgb(float *color, + float reff = 2.5, float system = system_gamma) +{ + color[0] = pow(color[0], system/reff); + color[1] = pow(color[1], system/reff); + color[2] = pow(color[2], system/reff); +}; + +inline void gamma_restore_c(float *color, + float reff = 2.5, float system = system_gamma) +{ + *color = pow(*color, system/reff); +}; + + #endif // _SG_COLORS_HXX -- 2.39.5