diff --git a/environment/skydome.cpp b/environment/skydome.cpp index 92cdbaa6..08bde1da 100644 --- a/environment/skydome.cpp +++ b/environment/skydome.cpp @@ -185,7 +185,7 @@ float CSkyDome::PerezFunctionO2( float Perezcoeffs[ 5 ], const float Icostheta, void CSkyDome::RebuildColors() { float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; - auto gammacorrection = glm::mix( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); + auto gammacorrection = glm::mix( glm::vec3( 1.0f ), glm::vec3( 0.45f ), twilightfactor ); // get zenith luminance float const chi = ( (4.0f / 9.0f) - (m_turbidity / 120.0f) ) * ( M_PI - (2.0f * m_thetasun) ); @@ -211,7 +211,7 @@ void CSkyDome::RebuildColors() { // trough all vertices glm::vec3 vertex; - glm::vec3 color, colorconverter, shiftedcolor; + glm::vec3 color, colorconverter; for ( unsigned int i = 0; i < m_vertices.size(); ++i ) { // grab it @@ -258,9 +258,7 @@ void CSkyDome::RebuildColors() { colorconverter.z = 1.0f - std::exp( -m_expfactor * colorconverter.z ); } - if( colorconverter.z > 0.85f ) { - colorconverter.z = 0.85f + ( colorconverter.z - 0.85f ) * 0.35f; - } + colorconverter.z = std::pow( std::max( colorconverter.z, 0.0f ), gammacorrection.x ); colorconverter.y = std::clamp( colorconverter.y * Global.m_skysaturationcorrection, 0.0f, 1.0f ); // desaturate sky colour, based on overcast level @@ -277,12 +275,10 @@ void CSkyDome::RebuildColors() { // this height-based factor is reduced the farther the sun is up in the sky float const shiftfactor = std::clamp( std::lerp(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f ); // h = 210 makes for 'typical' sky tone - shiftedcolor = glm::vec3( 210.0f, colorconverter.y, colorconverter.z ); - shiftedcolor = colors::HSVtoRGB( shiftedcolor ); + glm::vec3 const skytonecolor = colors::HSVtoRGB( glm::vec3( 210.0f, 0.5f, colorconverter.z ) ); - color = colors::HSVtoRGB(colorconverter); - - color = glm::mix( color, shiftedcolor, shiftfactor * Global.m_skyhuecorrection ); + color = colors::HSVtoRGB( colorconverter ); + color = glm::mix( color, skytonecolor, shiftfactor * Global.m_skyhuecorrection ); // crude correction for the times where the model breaks (late night) // TODO: use proper night sky calculation for these times instead @@ -295,10 +291,15 @@ void CSkyDome::RebuildColors() { color.y = 0.65f * color.z; } // simple gradient, darkening towards the top - color *= std::clamp( ( 1.0f - vertex.y ), 0.2f, 1.f ); + color *= std::clamp( ( 1.0f - vertex.y * 0.75f ), 0.0f, 1.f ); + + float const horizonboost = 1.5f + m_overcast; + float const horizonbandwidth = 0.2f; // boost tapers to 0 by ~11.5 degrees elevation + float const horizonband = std::clamp( 1.0f - vertex.y / horizonbandwidth, 0.0f, 1.0f ); + + color *= std::lerp( 1.0, horizonboost, horizonband ); + //color *= ( 0.25f - vertex.y ); - // gamma correction - color = glm::pow( color, gammacorrection ); m_colours[ i ] = color; averagecolor += color; if( ( m_vertices.size() - i ) <= ( m_tesselation * 10 + 10 ) ) {