From 543f1b790289b0173fdcbecec5c810e7a3e0d471 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 8 Oct 2014 12:45:01 +0200 Subject: [PATCH] Set sun color below horizon Thorsten Renk: The following patch sets the sun color to alpha=0 when the sun is below the local horizon, removing the oddity that the sun is seen 'through' the terrain when the terrain at large distance is rendered by the skydome. --- simgear/scene/sky/oursun.cxx | 12 +++++++++++- simgear/scene/sky/oursun.hxx | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/simgear/scene/sky/oursun.cxx b/simgear/scene/sky/oursun.cxx index a267034f..f4b049ee 100644 --- a/simgear/scene/sky/oursun.cxx +++ b/simgear/scene/sky/oursun.cxx @@ -52,7 +52,7 @@ using namespace simgear; // Constructor SGSun::SGSun( void ) : visibility(-9999.0), prev_sun_angle(-9999.0), path_distance(60000.0), - sun_exp2_punch_through(7.0e-06) + sun_exp2_punch_through(7.0e-06), horizon_angle(0.0) { } @@ -341,6 +341,13 @@ bool SGSun::repaint( double sun_angle, double new_visibility ) { gamma_correct_rgb( scene_color._v ); gamma_correct_rgb( sun_color._v ); + if (sun_angle >91.0 * 3.1415/180.0 + horizon_angle) + { + sun_color[3] = 0; + o_halo_color[3]=0; + i_halo_color[3]=0; + } + (*sun_cl)[0] = sun_color; sun_cl->dirty(); (*scene_cl)[0] = scene_color; @@ -404,6 +411,9 @@ bool SGSun::reposition( double rightAscension, double declination, if ( alt_half < 0.0 ) alt_half = 0.0; + //angle at which the sun is visible below the horizon + horizon_angle = acos(r_earth/position_radius); + // Push the data to the property tree, so it can be used in the enviromental code if ( env_node ){ env_node->setDoubleValue( "atmosphere/altitude-troposphere-top", r_tropo - r_earth ); diff --git a/simgear/scene/sky/oursun.hxx b/simgear/scene/sky/oursun.hxx index 3414c862..bd1f3db1 100644 --- a/simgear/scene/sky/oursun.hxx +++ b/simgear/scene/sky/oursun.hxx @@ -51,6 +51,7 @@ class SGSun : public SGReferenced { // distance of light traveling through the atmosphere double path_distance; double sun_exp2_punch_through; + double horizon_angle; SGPropertyNode_ptr env_node;