mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
virtual opengl color, overcast level based tweaks to light glare and freespot strength, precipitation based fog density adjustment, overcast level included in the light activation threshold
This commit is contained in:
@@ -584,7 +584,7 @@ void TAnimModel::RaPrepare()
|
|||||||
case ls_Dark: {
|
case ls_Dark: {
|
||||||
// zapalone, gdy ciemno
|
// zapalone, gdy ciemno
|
||||||
state = (
|
state = (
|
||||||
Global.fLuminance <= (
|
Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= (
|
||||||
lsLights[ i ] == static_cast<float>( ls_Dark ) ?
|
lsLights[ i ] == static_cast<float>( ls_Dark ) ?
|
||||||
DefaultDarkThresholdLevel :
|
DefaultDarkThresholdLevel :
|
||||||
( lsLights[ i ] - static_cast<float>( ls_Dark ) ) ) );
|
( lsLights[ i ] - static_cast<float>( ls_Dark ) ) ) );
|
||||||
@@ -594,7 +594,7 @@ void TAnimModel::RaPrepare()
|
|||||||
// like ls_dark but off late at night
|
// like ls_dark but off late at night
|
||||||
auto const simulationhour { simulation::Time.data().wHour };
|
auto const simulationhour { simulation::Time.data().wHour };
|
||||||
state = (
|
state = (
|
||||||
Global.fLuminance <= (
|
Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= (
|
||||||
lsLights[ i ] == static_cast<float>( ls_Home ) ?
|
lsLights[ i ] == static_cast<float>( ls_Home ) ?
|
||||||
DefaultDarkThresholdLevel :
|
DefaultDarkThresholdLevel :
|
||||||
( lsLights[ i ] - static_cast<float>( ls_Home ) ) ) );
|
( lsLights[ i ] - static_cast<float>( ls_Home ) ) ) );
|
||||||
|
|||||||
@@ -524,7 +524,8 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Ori
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
|
// NOTE: legacy leftover, potentially usable (but not really)
|
||||||
void TSegment::Render()
|
void TSegment::Render()
|
||||||
{
|
{
|
||||||
Math3D::vector3 pt;
|
Math3D::vector3 pt;
|
||||||
@@ -572,5 +573,5 @@ void TSegment::Render()
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -117,8 +117,10 @@ public:
|
|||||||
|
|
||||||
bool
|
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);
|
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
|
void
|
||||||
Render();
|
Render();
|
||||||
|
*/
|
||||||
inline
|
inline
|
||||||
double
|
double
|
||||||
GetLength() const {
|
GetLength() const {
|
||||||
|
|||||||
@@ -333,6 +333,9 @@
|
|||||||
<ClCompile Include="precipitation.cpp">
|
<ClCompile Include="precipitation.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="openglcolor.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Globals.h">
|
<ClInclude Include="Globals.h">
|
||||||
@@ -614,6 +617,9 @@
|
|||||||
<ClInclude Include="precipitation.h">
|
<ClInclude Include="precipitation.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="openglcolor.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="maszyna.rc">
|
<ResourceCompile Include="maszyna.rc">
|
||||||
|
|||||||
13
openglcolor.cpp
Normal file
13
openglcolor.cpp
Normal file
@@ -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;
|
||||||
69
openglcolor.h
Normal file
69
openglcolor.h
Normal file
@@ -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
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
@@ -341,6 +341,7 @@ opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_
|
|||||||
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
|
||||||
::glNewList( chunkrecord.list, GL_COMPILE );
|
::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 );
|
::glBegin( chunk.type );
|
||||||
for( auto const &vertex : chunk.vertices ) {
|
for( auto const &vertex : chunk.vertices ) {
|
||||||
if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
|
||||||
|
|||||||
29
renderer.cpp
29
renderer.cpp
@@ -1058,8 +1058,9 @@ opengl_renderer::setup_drawing( bool const Alpha ) {
|
|||||||
// setup fog
|
// setup fog
|
||||||
if( Global.fFogEnd > 0 ) {
|
if( Global.fFogEnd > 0 ) {
|
||||||
// fog setup
|
// fog setup
|
||||||
|
auto const adjustedfogrange { Global.fFogEnd / std::max( 1.f, Global.Overcast * 2.f ) };
|
||||||
::glFogfv( GL_FOG_COLOR, glm::value_ptr( Global.FogColor ) );
|
::glFogfv( GL_FOG_COLOR, glm::value_ptr( Global.FogColor ) );
|
||||||
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / Global.fFogEnd ) );
|
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / adjustedfogrange ) );
|
||||||
::glEnable( GL_FOG );
|
::glEnable( GL_FOG );
|
||||||
}
|
}
|
||||||
else { ::glDisable( GL_FOG ); }
|
else { ::glDisable( GL_FOG ); }
|
||||||
@@ -1461,7 +1462,7 @@ opengl_renderer::Render( world_environment *Environment ) {
|
|||||||
Environment->m_moon.render();
|
Environment->m_moon.render();
|
||||||
}
|
}
|
||||||
// render actual sun and moon
|
// 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_LIGHTING );
|
||||||
::glDisable( GL_ALPHA_TEST );
|
::glDisable( GL_ALPHA_TEST );
|
||||||
@@ -2529,15 +2530,16 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
|||||||
0.f, 1.f );
|
0.f, 1.f );
|
||||||
// distance attenuation. NOTE: since it's fixed pipeline with built-in gamma correction we're using linear attenuation
|
// 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
|
// 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 ) {
|
if( lightlevel > 0.f ) {
|
||||||
// material configuration:
|
// 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 );
|
Bind_Material( null_handle );
|
||||||
::glPointSize( std::max( 3.f, 5.f * distancefactor * anglefactor ) );
|
::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 );
|
::glDisable( GL_LIGHTING );
|
||||||
::glEnable( GL_BLEND );
|
::glEnable( GL_BLEND );
|
||||||
|
|
||||||
@@ -2580,7 +2582,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
|||||||
if( Global.fLuminance < Submodel->fLight ) {
|
if( Global.fLuminance < Submodel->fLight ) {
|
||||||
|
|
||||||
// material configuration:
|
// material configuration:
|
||||||
::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT );
|
::glPushAttrib( GL_ENABLE_BIT );
|
||||||
|
|
||||||
Bind_Material( null_handle );
|
Bind_Material( null_handle );
|
||||||
::glDisable( GL_LIGHTING );
|
::glDisable( GL_LIGHTING );
|
||||||
@@ -3352,7 +3354,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
|
|||||||
}
|
}
|
||||||
else if( Submodel->eType == TP_FREESPOTLIGHT ) {
|
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
|
// 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
|
// TODO: separate instance data from reusable geometry
|
||||||
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
|
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'
|
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 ) {
|
if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) {
|
||||||
// only bother if the viewer is inside the visibility cone
|
// only bother if the viewer is inside the visibility cone
|
||||||
if( Global.Overcast > 1.0 ) {
|
auto glarelevel { clamp<float>(
|
||||||
// increase the glare in rainy/foggy conditions
|
0.6f
|
||||||
glarelevel += std::max( 0.f, 0.5f * ( Global.Overcast - 1.f ) );
|
- 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
|
// scale it down based on view angle
|
||||||
glarelevel *= ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle );
|
glarelevel *= ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle );
|
||||||
// reduce the glare in bright daylight
|
|
||||||
glarelevel = clamp( glarelevel - static_cast<float>(Global.fLuminance), 0.f, 1.f );
|
|
||||||
|
|
||||||
if( glarelevel > 0.0f ) {
|
if( glarelevel > 0.0f ) {
|
||||||
// setup
|
// 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 );
|
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 ], glarelevel );
|
||||||
|
|||||||
1
stdafx.h
1
stdafx.h
@@ -104,6 +104,7 @@
|
|||||||
#include <glm/gtx/norm.hpp>
|
#include <glm/gtx/norm.hpp>
|
||||||
|
|
||||||
#include "openglmatrixstack.h"
|
#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
|
// imgui.h comes with its own operator new which gets wrecked by dbg_new, so we temporarily disable the latter
|
||||||
#ifdef DBG_NEW
|
#ifdef DBG_NEW
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ ui_layer::render() {
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
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_LIGHTING );
|
||||||
glDisable( GL_DEPTH_TEST );
|
glDisable( GL_DEPTH_TEST );
|
||||||
glDisable( GL_ALPHA_TEST );
|
glDisable( GL_ALPHA_TEST );
|
||||||
|
|||||||
Reference in New Issue
Block a user