diff --git a/AnimModel.cpp b/AnimModel.cpp index b77987ce..be263b5b 100644 --- a/AnimModel.cpp +++ b/AnimModel.cpp @@ -584,7 +584,7 @@ void TAnimModel::RaPrepare() case ls_Dark: { // zapalone, gdy ciemno state = ( - Global.fLuminance <= ( + Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= ( lsLights[ i ] == static_cast( ls_Dark ) ? DefaultDarkThresholdLevel : ( lsLights[ i ] - static_cast( ls_Dark ) ) ) ); @@ -594,7 +594,7 @@ void TAnimModel::RaPrepare() // like ls_dark but off late at night auto const simulationhour { simulation::Time.data().wHour }; state = ( - Global.fLuminance <= ( + Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= ( lsLights[ i ] == static_cast( ls_Home ) ? DefaultDarkThresholdLevel : ( lsLights[ i ] - static_cast( ls_Home ) ) ) ); diff --git a/Segment.cpp b/Segment.cpp index 5f2e16b4..97b5b877 100644 --- a/Segment.cpp +++ b/Segment.cpp @@ -524,7 +524,8 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Ori } return true; }; - +/* +// NOTE: legacy leftover, potentially usable (but not really) void TSegment::Render() { Math3D::vector3 pt; @@ -572,5 +573,5 @@ void TSegment::Render() glEnd(); } } - +*/ //--------------------------------------------------------------------------- diff --git a/Segment.h b/Segment.h index 81970cd9..2304a62d 100644 --- a/Segment.h +++ b/Segment.h @@ -117,8 +117,10 @@ public: bool RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Origin, gfx::basic_vertex const *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, float fOffsetX = 0.f, glm::vec3 **p = nullptr, bool bRender = true); +/* void Render(); +*/ inline double GetLength() const { diff --git a/maszyna.vcxproj.filters b/maszyna.vcxproj.filters index 761c958b..bdbf15fc 100644 --- a/maszyna.vcxproj.filters +++ b/maszyna.vcxproj.filters @@ -333,6 +333,9 @@ Source Files + + Source Files + @@ -614,6 +617,9 @@ Header Files + + Header Files + diff --git a/openglcolor.cpp b/openglcolor.cpp new file mode 100644 index 00000000..65e36d51 --- /dev/null +++ b/openglcolor.cpp @@ -0,0 +1,13 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "openglcolor.h" + +opengl_color OpenGLColor; diff --git a/openglcolor.h b/openglcolor.h new file mode 100644 index 00000000..a40f0732 --- /dev/null +++ b/openglcolor.h @@ -0,0 +1,69 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +// encapsulation of the fixed pipeline opengl color +class opengl_color { + +public: +// constructors: + opengl_color() = default; + +// methods: + inline + void + color3( glm::vec3 const &Color ) { + return color4( glm::vec4{ Color, 1.f } ); } + inline + void + color3( float const Red, float const Green, float const Blue ) { + return color3( glm::vec3 { Red, Green, Blue } ); } + inline + void + color3( float const *Value ) { + return color3( glm::make_vec3( Value ) ); } + inline + void + color4( glm::vec4 const &Color ) { + if( Color != m_color ) { + m_color = Color; + ::glColor4fv( glm::value_ptr( m_color ) ); } } + inline + void + color4( float const Red, float const Green, float const Blue, float const Alpha ) { + return color4( glm::vec4{ Red, Green, Blue, Alpha } ); } + inline + void + color4( float const *Value ) { + return color4( glm::make_vec4( Value ) ); + } + inline + glm::vec4 const & + data() const { + return m_color; } + inline + float const * + data_array() const { + return glm::value_ptr( m_color ); } + +private: +// members: + glm::vec4 m_color { -1 }; +}; + +extern opengl_color OpenGLColor; + +// NOTE: standard opengl calls re-definitions +#define glColor3f OpenGLColor.color3 +#define glColor3fv OpenGLColor.color3 +#define glColor4f OpenGLColor.color4 +#define glColor4fv OpenGLColor.color4 + +//--------------------------------------------------------------------------- diff --git a/openglgeometrybank.cpp b/openglgeometrybank.cpp index 02fde9db..ba29170e 100644 --- a/openglgeometrybank.cpp +++ b/openglgeometrybank.cpp @@ -341,6 +341,7 @@ opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_ auto const &chunk = gfx::geometry_bank::chunk( Geometry ); ::glNewList( chunkrecord.list, GL_COMPILE ); + ::glColor3f( -1.f, -1.f, -1.f ); // HACK: force the opengl color wrapper to include color call in the display list regardless of currently active color ::glBegin( chunk.type ); for( auto const &vertex : chunk.vertices ) { if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); } diff --git a/renderer.cpp b/renderer.cpp index 28e9d0e0..9a0adf7d 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -1058,8 +1058,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 ) }; ::glFogfv( GL_FOG_COLOR, glm::value_ptr( Global.FogColor ) ); - ::glFogf( GL_FOG_DENSITY, static_cast( 1.0 / Global.fFogEnd ) ); + ::glFogf( GL_FOG_DENSITY, static_cast( 1.0 / adjustedfogrange ) ); ::glEnable( GL_FOG ); } else { ::glDisable( GL_FOG ); } @@ -1461,7 +1462,7 @@ opengl_renderer::Render( world_environment *Environment ) { Environment->m_moon.render(); } // render actual sun and moon - ::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT ); + ::glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT ); ::glDisable( GL_LIGHTING ); ::glDisable( GL_ALPHA_TEST ); @@ -2529,15 +2530,16 @@ opengl_renderer::Render( TSubModel *Submodel ) { 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 distancefactor { std::max( 0.5f, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / Submodel->fSquareMaxDist ) }; + float const precipitationfactor { std::max( 1.f, Global.Overcast - 1.f ) }; if( lightlevel > 0.f ) { // material configuration: - ::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT ); + ::glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT ); Bind_Material( null_handle ); ::glPointSize( std::max( 3.f, 5.f * distancefactor * anglefactor ) ); - ::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], lightlevel * anglefactor ); + ::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], std::min( 1.f, lightlevel * anglefactor * precipitationfactor ) ); ::glDisable( GL_LIGHTING ); ::glEnable( GL_BLEND ); @@ -2580,7 +2582,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { if( Global.fLuminance < Submodel->fLight ) { // material configuration: - ::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT ); + ::glPushAttrib( GL_ENABLE_BIT ); Bind_Material( null_handle ); ::glDisable( GL_LIGHTING ); @@ -3352,7 +3354,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { } else if( Submodel->eType == TP_FREESPOTLIGHT ) { - if( Global.fLuminance < Submodel->fLight ) { + if( ( Global.fLuminance < Submodel->fLight ) || ( Global.Overcast > 1.f ) ) { // NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh // TODO: separate instance data from reusable geometry auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); @@ -3367,18 +3369,17 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { 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 - if( Global.Overcast > 1.0 ) { - // increase the glare in rainy/foggy conditions - glarelevel += std::max( 0.f, 0.5f * ( Global.Overcast - 1.f ) ); - } + auto glarelevel { clamp( + 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 + 0.f, 1.f ) }; // scale it down based on view angle glarelevel *= ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle ); - // reduce the glare in bright daylight - glarelevel = clamp( glarelevel - static_cast(Global.fLuminance), 0.f, 1.f ); if( glarelevel > 0.0f ) { // setup - ::glPushAttrib( GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT ); + ::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 ); diff --git a/stdafx.h b/stdafx.h index 145bed1f..c59fc775 100644 --- a/stdafx.h +++ b/stdafx.h @@ -104,6 +104,7 @@ #include #include "openglmatrixstack.h" +#include "openglcolor.h" // imgui.h comes with its own operator new which gets wrecked by dbg_new, so we temporarily disable the latter #ifdef DBG_NEW diff --git a/uilayer.cpp b/uilayer.cpp index c5ed4262..94ccfaea 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -161,7 +161,7 @@ ui_layer::render() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT ); // blendfunc included since 3rd party gui doesn't play nice + glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT ); // blendfunc included since 3rd party gui doesn't play nice glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); glDisable( GL_ALPHA_TEST );