From f75656ea59bf869afd6ef242caddd890a8247bef Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sun, 12 Sep 2010 11:06:14 +0200 Subject: [PATCH] Allow for scenery de-saturation --- src/Time/light.cxx | 13 ++++++++++++- src/Time/light.hxx | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Time/light.cxx b/src/Time/light.cxx index 08d0fbf72..24d1c7caf 100644 --- a/src/Time/light.cxx +++ b/src/Time/light.cxx @@ -108,6 +108,7 @@ FGLight::FGLight () _cloud_color(0, 0, 0, 0), _adj_fog_color(0, 0, 0, 0), _adj_sky_color(0, 0, 0, 0), + _saturation(1.0), _dt_total(0) { } @@ -172,6 +173,7 @@ void FGLight::reinit () { void FGLight::bind () { SGPropertyNode *prop = globals->get_props(); prop->tie("/sim/time/sun-angle-rad",SGRawValuePointer(&_sun_angle)); + prop->tie("/rendering/scene/saturation",SGRawValuePointer(&_saturation)); prop->tie("/rendering/scene/ambient/red",SGRawValuePointer(&_scene_ambient[0])); prop->tie("/rendering/scene/ambient/green",SGRawValuePointer(&_scene_ambient[1])); prop->tie("/rendering/scene/ambient/blue",SGRawValuePointer(&_scene_ambient[2])); @@ -201,6 +203,7 @@ void FGLight::bind () { void FGLight::unbind () { SGPropertyNode *prop = globals->get_props(); prop->untie("/sim/time/sun-angle-rad"); + prop->untie("/rendering/scene/saturation"); prop->untie("/rendering/scene/ambient/red"); prop->untie("/rendering/scene/ambient/green"); prop->untie("/rendering/scene/ambient/blue"); @@ -251,11 +254,19 @@ void FGLight::update_sky_color () { float deg = _sun_angle * SGD_RADIANS_TO_DEGREES; SG_LOG( SG_EVENT, SG_DEBUG, " Sun angle = " << deg ); + if (_saturation < 0.0) _saturation = 0.0; + else if (_saturation > 1.0) _saturation = 1.0; + float ambient = _ambient_tbl->interpolate( deg ) + visibility_inv/10; float diffuse = _diffuse_tbl->interpolate( deg ); float specular = _specular_tbl->interpolate( deg ) * visibility_log; float sky_brightness = _sky_tbl->interpolate( deg ); + ambient *= _saturation; + diffuse *= _saturation; + specular *= _saturation; + sky_brightness *= _saturation; + SG_LOG( SG_EVENT, SG_DEBUG, " ambient = " << ambient << " diffuse = " << diffuse << " specular = " << specular << " sky = " << sky_brightness ); @@ -394,7 +405,7 @@ void FGLight::update_adj_fog_color () { sif = 1e-4; float rf1 = fabs((hor_rotation - SGD_PI) / SGD_PI); // 0.0 .. 1.0 - float rf2 = avf * pow(rf1*rf1, 1/sif) * 1.0639; + float rf2 = avf * pow(rf1*rf1, 1/sif) * 1.0639 * _saturation; float rf3 = 1.0 - rf2; gamma = system_gamma * (0.9 - sif*avf); diff --git a/src/Time/light.hxx b/src/Time/light.hxx index ebc509966..42a9f27d8 100644 --- a/src/Time/light.hxx +++ b/src/Time/light.hxx @@ -96,6 +96,7 @@ private: // clear sky and fog color adjusted for sunset effects SGVec4f _adj_fog_color; SGVec4f _adj_sky_color; + float _saturation; double _dt_total; @@ -131,7 +132,6 @@ public: inline const SGVec4f& adj_fog_color () const { return _adj_fog_color; } inline const SGVec4f& adj_sky_color () const { return _adj_sky_color; } - // Sun related functions inline double get_sun_angle () const { return _sun_angle; } -- 2.39.5