16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-20 10:19:19 +02:00

fog color calculation fix

This commit is contained in:
tmj-fstate
2018-02-21 23:13:06 +01:00
parent 40e77acb69
commit da9b1431ea
5 changed files with 51 additions and 16 deletions

View File

@@ -68,7 +68,7 @@ struct global_settings {
float fFriction{ 1.f }; // mnożnik tarcia - KURS90
bool bLiveTraction{ true };
float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere
GLfloat FogColor[ 3 ] = { 0.6f, 0.7f, 0.8f };
glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f };
double fFogStart{ 1700 };
double fFogEnd{ 2000 };
std::string Season{}; // season of the year, based on simulation date

View File

@@ -1587,7 +1587,8 @@ TWorld::Update_UI() {
Acc = ( vehicle->MoverParameters->Vel - VelPrev ) / 3.6;
VelPrev = vehicle->MoverParameters->Vel;
}
uitextline2 += ( "; As=" ) + to_string( Acc, 2 ); // przyspieszenie wzdłużne
uitextline2 += "; As=" + to_string( Acc, 2 ); // przyspieszenie wzdłużne
uitextline2 += " eAngle=" + to_string( std::cos( vehicle->MoverParameters->eAngle ), 2 );
uitextline3 =
"cyl.ham. " + to_string( vehicle->MoverParameters->BrakePress, 2 )
@@ -2214,17 +2215,16 @@ world_environment::update() {
// tonal impact of skydome color is inversely proportional to how high the sun is above the horizon
// (this is pure conjecture, aimed more to 'look right' than be accurate)
float const ambienttone = clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f );
Global.DayLight.ambient[ 0 ] = interpolate( skydomehsv.z, skydomecolour.x, ambienttone );
Global.DayLight.ambient[ 1 ] = interpolate( skydomehsv.z, skydomecolour.y, ambienttone );
Global.DayLight.ambient[ 2 ] = interpolate( skydomehsv.z, skydomecolour.z, ambienttone );
Global.DayLight.ambient[ 0 ] = interpolate( skydomehsv.z, skydomecolour.r, ambienttone );
Global.DayLight.ambient[ 1 ] = interpolate( skydomehsv.z, skydomecolour.g, ambienttone );
Global.DayLight.ambient[ 2 ] = interpolate( skydomehsv.z, skydomecolour.b, ambienttone );
Global.fLuminance = intensity;
// update the fog. setting it to match the average colour of the sky dome is cheap
// but quite effective way to make the distant items blend with background better
Global.FogColor[ 0 ] = skydomecolour.x;
Global.FogColor[ 1 ] = skydomecolour.y;
Global.FogColor[ 2 ] = skydomecolour.z;
// NOTE: base brightness calculation provides scaled up value, so we bring it back to 'real' one here
Global.FogColor = m_skydome.GetAverageHorizonColor();
}
void

View File

@@ -1027,7 +1027,7 @@ opengl_renderer::setup_drawing( bool const Alpha ) {
// setup fog
if( Global.fFogEnd > 0 ) {
// fog setup
::glFogfv( GL_FOG_COLOR, Global.FogColor );
::glFogfv( GL_FOG_COLOR, glm::value_ptr( Global.FogColor ) );
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / Global.fFogEnd ) );
::glEnable( GL_FOG );
}
@@ -1808,6 +1808,37 @@ opengl_renderer::Render( cell_sequence::iterator First, cell_sequence::iterator
Render( memcell );
}
}
#endif
#ifdef EU07_USE_DEBUG_CULLING
// debug
::glLineWidth( 2.f );
float const width = cell->m_area.radius;
float const height = cell->m_area.radius * 0.2f;
glDisable( GL_LIGHTING );
glDisable( GL_TEXTURE_2D );
glColor3ub( 255, 128, 128 );
glBegin( GL_LINE_LOOP );
glVertex3f( -width, height, width );
glVertex3f( -width, height, -width );
glVertex3f( width, height, -width );
glVertex3f( width, height, width );
glEnd();
glBegin( GL_LINE_LOOP );
glVertex3f( -width, 0, width );
glVertex3f( -width, 0, -width );
glVertex3f( width, 0, -width );
glVertex3f( width, 0, width );
glEnd();
glBegin( GL_LINES );
glVertex3f( -width, height, width ); glVertex3f( -width, 0, width );
glVertex3f( -width, height, -width ); glVertex3f( -width, 0, -width );
glVertex3f( width, height, -width ); glVertex3f( width, 0, -width );
glVertex3f( width, height, width ); glVertex3f( width, 0, width );
glEnd();
glColor3ub( 255, 255, 255 );
glEnable( GL_TEXTURE_2D );
glEnable( GL_LIGHTING );
glLineWidth( 1.f );
#endif
// post-render cleanup
::glPopMatrix();

View File

@@ -243,7 +243,7 @@ void CSkyDome::RebuildColors() {
zenithluminance = PerezFunctionO1( perezluminance, m_thetasun, zenithluminance );
// start with fresh average for the new pass
glm::vec3 averagecolor { 0.0f, 0.0f, 0.0f };
glm::vec3 averagecolor, averagehorizoncolor;
// trough all vertices
glm::vec3 vertex;
@@ -333,14 +333,16 @@ void CSkyDome::RebuildColors() {
}
// save
m_colours[ i ] = color;
averagecolor += color * 8.0f; // save for edge cases each vertex goes in 8 triangles
averagecolor += color;
if( ( m_vertices.size() - i ) <= ( m_tesselation * 2 ) ) {
// calculate horizon colour from the bottom band of tris
averagehorizoncolor += color;
}
}
// NOTE: average reduced to 25% makes nice tint value for clouds lit from behind
// down the road we could interpolate between it and full strength average, to improve accuracy of cloud appearance
m_averagecolour = averagecolor / static_cast<float>( m_indices.size() );
m_averagecolour.r = std::max( m_averagecolour.r, 0.0f );
m_averagecolour.g = std::max( m_averagecolour.g, 0.0f );
m_averagecolour.b = std::max( m_averagecolour.b, 0.0f );
m_averagecolour = glm::max( glm::vec3(), averagecolor / static_cast<float>( m_vertices.size() ) );
m_averagehorizoncolour = glm::max( glm::vec3(), averagehorizoncolor / static_cast<float>( m_tesselation * 2 ) );
if( m_coloursbuffer != -1 ) {
// the colour buffer was already initialized, so on this run we update its content

View File

@@ -23,7 +23,8 @@ public:
void Render();
// retrieves average colour of the sky dome
glm::vec3 GetAverageColor() { return m_averagecolour; }
glm::vec3 GetAverageColor() { return m_averagecolour * 8.f / 6.f; }
glm::vec3 GetAverageHorizonColor() { return m_averagehorizoncolour; }
private:
// shading parametrs
@@ -35,6 +36,7 @@ private:
float m_overcast;
float m_gammacorrection;
glm::vec3 m_averagecolour;
glm::vec3 m_averagehorizoncolour;
// data
int const m_tesselation;