mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 03:09:18 +02:00
Merge branch 'tmj-dev' into milek-dev
This commit is contained in:
167
renderer.cpp
167
renderer.cpp
@@ -1083,9 +1083,9 @@ opengl_renderer::setup_drawing( bool const Alpha ) {
|
||||
// setup fog
|
||||
if( Global.fFogEnd > 0 ) {
|
||||
// fog setup
|
||||
auto const adjustedfogrange { Global.fFogEnd / std::max( 1.f, Global.Overcast * 2.f ) };
|
||||
m_fogrange = Global.fFogEnd / std::max( 1.f, Global.Overcast * 2.f );
|
||||
::glFogfv( GL_FOG_COLOR, glm::value_ptr( Global.FogColor ) );
|
||||
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / adjustedfogrange ) );
|
||||
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / m_fogrange ) );
|
||||
::glEnable( GL_FOG );
|
||||
}
|
||||
else { ::glDisable( GL_FOG ); }
|
||||
@@ -2434,7 +2434,20 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
Bind_Material( Submodel->m_material );
|
||||
}
|
||||
// ...colors...
|
||||
::glColor3fv( glm::value_ptr( Submodel->f4Diffuse ) ); // McZapkie-240702: zamiast ub
|
||||
if( Submodel->fVisible < 1.f ) {
|
||||
// setup
|
||||
::glAlphaFunc( GL_GREATER, 0.f );
|
||||
::glEnable( GL_BLEND );
|
||||
::glColor4f(
|
||||
Submodel->f4Diffuse.r,
|
||||
Submodel->f4Diffuse.g,
|
||||
Submodel->f4Diffuse.b,
|
||||
Submodel->fVisible );
|
||||
}
|
||||
else {
|
||||
::glColor3fv( glm::value_ptr( Submodel->f4Diffuse ) ); // McZapkie-240702: zamiast ub
|
||||
}
|
||||
// ...specular...
|
||||
if( ( true == m_renderspecular ) && ( m_sunlight.specular.a > 0.01f ) ) {
|
||||
// specular strength in legacy models is set uniformly to 150, 150, 150 so we scale it down for opaque elements
|
||||
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( Submodel->f4Specular * m_sunlight.specular.a * m_specularopaquescalefactor ) );
|
||||
@@ -2466,6 +2479,10 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
}
|
||||
*/
|
||||
// post-draw reset
|
||||
if( Submodel->fVisible < 1.f ) {
|
||||
::glAlphaFunc( GL_GREATER, 0.5f );
|
||||
::glDisable( GL_BLEND );
|
||||
}
|
||||
if( ( true == m_renderspecular ) && ( m_sunlight.specular.a > 0.01f ) ) {
|
||||
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( colors::none ) );
|
||||
}
|
||||
@@ -2557,42 +2574,65 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
float const anglefactor = clamp(
|
||||
( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ),
|
||||
0.f, 1.f );
|
||||
// distance attenuation. NOTE: since it's fixed pipeline with built-in gamma correction we're using linear attenuation
|
||||
// we're capping how much effect the distance attenuation can have, otherwise the lights get too tiny at regular distances
|
||||
float const distancefactor { std::max( 0.5f, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / Submodel->fSquareMaxDist ) };
|
||||
float const precipitationfactor { std::max( 1.f, Global.Overcast - 1.f ) };
|
||||
lightlevel *= anglefactor;
|
||||
float const precipitationfactor { interpolate( 1.f, 0.25f, clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ) };
|
||||
lightlevel *= precipitationfactor;
|
||||
|
||||
if( lightlevel > 0.f ) {
|
||||
// material configuration:
|
||||
::glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT );
|
||||
// distance attenuation. NOTE: since it's fixed pipeline with built-in gamma correction we're using linear attenuation
|
||||
// we're capping how much effect the distance attenuation can have, otherwise the lights get too tiny at regular distances
|
||||
float const distancefactor { std::max( 0.5f, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / Submodel->fSquareMaxDist ) };
|
||||
auto const pointsize { std::max( 3.f, 5.f * distancefactor * anglefactor ) };
|
||||
|
||||
// material configuration:
|
||||
Bind_Material( null_handle );
|
||||
::glPointSize( std::max( 3.f, 5.f * distancefactor * anglefactor ) );
|
||||
::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], std::min( 1.f, lightlevel * anglefactor * precipitationfactor ) );
|
||||
// limit impact of dense fog on the lights
|
||||
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / std::min<float>( Global.fFogEnd, m_fogrange * 2 ) ) );
|
||||
|
||||
::glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT );
|
||||
::glDisable( GL_LIGHTING );
|
||||
::glEnable( GL_BLEND );
|
||||
::glAlphaFunc( GL_GREATER, 0.f );
|
||||
|
||||
::glPushMatrix();
|
||||
::glLoadIdentity();
|
||||
::glTranslatef( lightcenter.x, lightcenter.y, lightcenter.z ); // początek układu zostaje bez zmian
|
||||
/*
|
||||
setup_shadow_color( colors::white );
|
||||
*/
|
||||
|
||||
auto const unitstate = m_unitstate;
|
||||
switch_units( m_unitstate.diffuse, false, false );
|
||||
|
||||
// main draw call
|
||||
if( Global.Overcast > 1.f ) {
|
||||
// fake fog halo
|
||||
float const fogfactor {
|
||||
interpolate(
|
||||
2.f, 1.f,
|
||||
clamp<float>( Global.fFogEnd / 2000, 0.f, 1.f ) )
|
||||
* std::max( 1.f, Global.Overcast ) };
|
||||
::glPointSize( pointsize * fogfactor );
|
||||
::glColor4f(
|
||||
Submodel->f4Diffuse[ 0 ],
|
||||
Submodel->f4Diffuse[ 1 ],
|
||||
Submodel->f4Diffuse[ 2 ],
|
||||
Submodel->fVisible * std::min( 1.f, lightlevel ) * 0.5f );
|
||||
::glDepthMask( GL_FALSE );
|
||||
m_geometry.draw( Submodel->m_geometry );
|
||||
::glDepthMask( GL_TRUE );
|
||||
}
|
||||
::glPointSize( pointsize );
|
||||
::glColor4f(
|
||||
Submodel->f4Diffuse[ 0 ],
|
||||
Submodel->f4Diffuse[ 1 ],
|
||||
Submodel->f4Diffuse[ 2 ],
|
||||
Submodel->fVisible * std::min( 1.f, lightlevel ) );
|
||||
m_geometry.draw( Submodel->m_geometry );
|
||||
|
||||
// post-draw reset
|
||||
// re-enable shadows
|
||||
/*
|
||||
setup_shadow_color( m_shadowcolor );
|
||||
*/
|
||||
switch_units( unitstate.diffuse, unitstate.shadows, unitstate.reflections );
|
||||
|
||||
::glPopMatrix();
|
||||
::glPopAttrib();
|
||||
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / m_fogrange ) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2649,7 +2689,9 @@ void
|
||||
opengl_renderer::Render( TTrack *Track ) {
|
||||
|
||||
if( ( Track->m_material1 == 0 )
|
||||
&& ( Track->m_material2 == 0 ) ) {
|
||||
&& ( Track->m_material2 == 0 )
|
||||
&& ( ( Track->eType != tt_Switch )
|
||||
|| ( Track->SwitchExtension->m_material3 == 0 ) ) ) {
|
||||
return;
|
||||
}
|
||||
if( false == Track->m_visible ) {
|
||||
@@ -2671,6 +2713,11 @@ opengl_renderer::Render( TTrack *Track ) {
|
||||
Bind_Material( Track->m_material2 );
|
||||
m_geometry.draw( std::begin( Track->Geometry2 ), std::end( Track->Geometry2 ) );
|
||||
}
|
||||
if( ( Track->eType == tt_Switch )
|
||||
&& ( Track->SwitchExtension->m_material3 != 0 ) ) {
|
||||
Bind_Material( Track->SwitchExtension->m_material3 );
|
||||
m_geometry.draw( Track->SwitchExtension->Geometry3 );
|
||||
}
|
||||
setup_environment_light();
|
||||
break;
|
||||
}
|
||||
@@ -2691,6 +2738,11 @@ opengl_renderer::Render( TTrack *Track ) {
|
||||
Bind_Material( Track->m_material2 );
|
||||
m_geometry.draw( std::begin( Track->Geometry2 ), std::end( Track->Geometry2 ) );
|
||||
}
|
||||
if( ( Track->eType == tt_Switch )
|
||||
&& ( Track->SwitchExtension->m_material3 != 0 ) ) {
|
||||
Bind_Material( Track->SwitchExtension->m_material3 );
|
||||
m_geometry.draw( Track->SwitchExtension->Geometry3 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case rendermode::pickcontrols:
|
||||
@@ -2717,6 +2769,7 @@ opengl_renderer::Render( scene::basic_cell::path_sequence::const_iterator First,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: render auto generated trackbeds together with regular trackbeds in pass 1, and all rails in pass 2
|
||||
// first pass, material 1
|
||||
for( auto first { First }; first != Last; ++first ) {
|
||||
|
||||
@@ -2807,6 +2860,53 @@ opengl_renderer::Render( scene::basic_cell::path_sequence::const_iterator First,
|
||||
}
|
||||
}
|
||||
}
|
||||
// third pass, material 3
|
||||
for( auto first { First }; first != Last; ++first ) {
|
||||
|
||||
auto const track { *first };
|
||||
|
||||
if( track->eType != tt_Switch ) {
|
||||
continue;
|
||||
}
|
||||
if( track->SwitchExtension->m_material3 == 0 ) {
|
||||
continue;
|
||||
}
|
||||
if( false == track->m_visible ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::color:
|
||||
case rendermode::reflections: {
|
||||
if( track->eEnvironment != e_flat ) {
|
||||
setup_environment_light( track->eEnvironment );
|
||||
}
|
||||
Bind_Material( track->SwitchExtension->m_material3 );
|
||||
m_geometry.draw( track->SwitchExtension->Geometry3 );
|
||||
if( track->eEnvironment != e_flat ) {
|
||||
// restore default lighting
|
||||
setup_environment_light();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case rendermode::shadows: {
|
||||
if( ( std::abs( track->fTexHeight1 ) < 0.35f )
|
||||
|| ( ( track->iCategoryFlag == 1 )
|
||||
&& ( track->eType != tt_Normal ) ) ) {
|
||||
// shadows are only calculated for high enough trackbeds
|
||||
continue;
|
||||
}
|
||||
Bind_Material( track->SwitchExtension->m_material3 );
|
||||
m_geometry.draw( track->SwitchExtension->Geometry3 );
|
||||
break;
|
||||
}
|
||||
case rendermode::pickscenery: // pick scenery mode uses piece-by-piece approach
|
||||
case rendermode::pickcontrols:
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// post-render reset
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::shadows: {
|
||||
@@ -3083,7 +3183,7 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) {
|
||||
::glLineWidth(
|
||||
clamp(
|
||||
0.5f * linealpha + Traction->WireThickness * Traction->radius() / 1000.f,
|
||||
1.f, 1.5f ) );
|
||||
1.f, 1.75f ) );
|
||||
// McZapkie-261102: kolor zalezy od materialu i zasniedzenia
|
||||
::glColor4fv(
|
||||
glm::value_ptr(
|
||||
@@ -3401,24 +3501,28 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
|
||||
static_cast<float>( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery
|
||||
Submodel->fCosViewAngle = glm::dot( glm::normalize( modelview * glm::vec4( 0.f, 0.f, -1.f, 1.f ) - lightcenter ), glm::normalize( -lightcenter ) );
|
||||
|
||||
float glarelevel = 0.6f; // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
|
||||
if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) {
|
||||
// only bother if the viewer is inside the visibility cone
|
||||
auto glarelevel { clamp<float>(
|
||||
0.6f
|
||||
- Global.fLuminance // reduce the glare in bright daylight
|
||||
+ std::max( 0.f, Global.Overcast - 1.f ), // increase the glare in rainy/foggy conditions
|
||||
// luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
|
||||
auto glarelevel { clamp(
|
||||
std::max<float>(
|
||||
0.6f - Global.fLuminance, // reduce the glare in bright daylight
|
||||
Global.Overcast - 1.f ), // ensure some glare in rainy/foggy conditions
|
||||
0.f, 1.f ) };
|
||||
// scale it down based on view angle
|
||||
glarelevel *= ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle );
|
||||
// view angle attenuation
|
||||
float const anglefactor { clamp(
|
||||
( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ),
|
||||
0.f, 1.f ) };
|
||||
glarelevel *= anglefactor;
|
||||
|
||||
if( glarelevel > 0.0f ) {
|
||||
// setup
|
||||
::glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT );
|
||||
|
||||
Bind_Texture( m_glaretexture );
|
||||
::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], glarelevel );
|
||||
::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], Submodel->fVisible * glarelevel );
|
||||
::glDisable( GL_LIGHTING );
|
||||
::glDisable( GL_FOG );
|
||||
::glDepthMask( GL_FALSE );
|
||||
::glBlendFunc( GL_SRC_ALPHA, GL_ONE );
|
||||
|
||||
@@ -3823,8 +3927,13 @@ opengl_renderer::Init_caps() {
|
||||
+ " Vendor: " + std::string( (char *)glGetString( GL_VENDOR ) )
|
||||
+ " OpenGL Version: " + oglversion );
|
||||
|
||||
#ifdef EU07_USEIMGUIIMPLOPENGL2
|
||||
if( !GLEW_VERSION_1_5 ) {
|
||||
ErrorLog( "Requires openGL >= 1.5" );
|
||||
#else
|
||||
if( !GLEW_VERSION_3_0 ) {
|
||||
ErrorLog( "Requires openGL >= 3.0" ); // technically 1.5 for now, but imgui wants more
|
||||
ErrorLog( "Requires openGL >= 3.0" );
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user