mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 13:39:18 +02:00
basic smoke quality settings
This commit is contained in:
18
Globals.cpp
18
Globals.cpp
@@ -175,12 +175,6 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
Parser.getTokens();
|
Parser.getTokens();
|
||||||
Parser >> DisabledLogTypes;
|
Parser >> DisabledLogTypes;
|
||||||
}
|
}
|
||||||
else if( token == "adjustscreenfreq" )
|
|
||||||
{
|
|
||||||
// McZapkie-240403 - czestotliwosc odswiezania ekranu
|
|
||||||
Parser.getTokens();
|
|
||||||
Parser >> bAdjustScreenFreq;
|
|
||||||
}
|
|
||||||
else if (token == "mousescale")
|
else if (token == "mousescale")
|
||||||
{
|
{
|
||||||
// McZapkie-060503 - czulosc ruchu myszy (krecenia glowa)
|
// McZapkie-060503 - czulosc ruchu myszy (krecenia glowa)
|
||||||
@@ -367,6 +361,18 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
Parser.getTokens();
|
Parser.getTokens();
|
||||||
Parser >> RenderCabShadowsRange;
|
Parser >> RenderCabShadowsRange;
|
||||||
}
|
}
|
||||||
|
else if( token == "gfx.smoke" ) {
|
||||||
|
// smoke visualization toggle
|
||||||
|
Parser.getTokens();
|
||||||
|
Parser >> Smoke;
|
||||||
|
}
|
||||||
|
else if( token == "gfx.smoke.fidelity" ) {
|
||||||
|
// smoke visualization fidelity
|
||||||
|
float smokefidelity;
|
||||||
|
Parser.getTokens();
|
||||||
|
Parser >> smokefidelity;
|
||||||
|
SmokeFidelity = clamp( smokefidelity, 1.f, 4.f );
|
||||||
|
}
|
||||||
else if (token == "smoothtraction")
|
else if (token == "smoothtraction")
|
||||||
{
|
{
|
||||||
// podwójna jasność ambient
|
// podwójna jasność ambient
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ struct global_settings {
|
|||||||
int iMultisampling{ 2 }; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px
|
int iMultisampling{ 2 }; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px
|
||||||
bool bSmoothTraction{ true }; // wygładzanie drutów starym sposobem
|
bool bSmoothTraction{ true }; // wygładzanie drutów starym sposobem
|
||||||
float SplineFidelity{ 1.f }; // determines segment size during conversion of splines to geometry
|
float SplineFidelity{ 1.f }; // determines segment size during conversion of splines to geometry
|
||||||
|
bool Smoke{ true }; // toggles smoke simulation and visualization
|
||||||
|
float SmokeFidelity{ 1.f }; // determines amount of generated smoke particles
|
||||||
bool ResourceSweep{ true }; // gfx resource garbage collection
|
bool ResourceSweep{ true }; // gfx resource garbage collection
|
||||||
bool ResourceMove{ false }; // gfx resources are moved between cpu and gpu side instead of sending a copy
|
bool ResourceMove{ false }; // gfx resources are moved between cpu and gpu side instead of sending a copy
|
||||||
bool compress_tex{ true }; // all textures are compressed on gpu side
|
bool compress_tex{ true }; // all textures are compressed on gpu side
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ smoke_source::particle_emitter::initialize( smoke_particle &Particle ) {
|
|||||||
|
|
||||||
Particle.rotation = glm::radians( Random( 0, 360 ) );
|
Particle.rotation = glm::radians( Random( 0, 360 ) );
|
||||||
Particle.size = Random( size[ value_limit::min ], size[ value_limit::max ] );
|
Particle.size = Random( size[ value_limit::min ], size[ value_limit::max ] );
|
||||||
Particle.opacity = Random( opacity[ value_limit::min ], opacity[ value_limit::max ] );
|
Particle.opacity = Random( opacity[ value_limit::min ], opacity[ value_limit::max ] ) / Global.SmokeFidelity;
|
||||||
Particle.age = 0;
|
Particle.age = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ smoke_source::initialize() {
|
|||||||
m_particles.reserve(
|
m_particles.reserve(
|
||||||
// put a cap on number of particles in a single source. TBD, TODO: make it part of he source configuration?
|
// put a cap on number of particles in a single source. TBD, TODO: make it part of he source configuration?
|
||||||
std::min(
|
std::min(
|
||||||
500,
|
static_cast<int>( 500 * Global.SmokeFidelity ),
|
||||||
// NOTE: given nature of the smoke we're presuming opacity decreases over time and the particle is killed when it reaches 0
|
// NOTE: given nature of the smoke we're presuming opacity decreases over time and the particle is killed when it reaches 0
|
||||||
// this gives us estimate of longest potential lifespan of single particle, and how many particles total can there be at any given time
|
// this gives us estimate of longest potential lifespan of single particle, and how many particles total can there be at any given time
|
||||||
// TBD, TODO: explicit lifespan variable as part of the source configuration?
|
// TBD, TODO: explicit lifespan variable as part of the source configuration?
|
||||||
@@ -150,10 +150,10 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
|
|||||||
glm::dvec3{ std::numeric_limits<double>::lowest() } };
|
glm::dvec3{ std::numeric_limits<double>::lowest() } };
|
||||||
|
|
||||||
m_spawncount = (
|
m_spawncount = (
|
||||||
Onlydespawn ?
|
( ( false == Global.Smoke ) || ( true == Onlydespawn ) ) ?
|
||||||
0.f :
|
0.f :
|
||||||
std::min<float>(
|
std::min<float>(
|
||||||
m_spawncount + ( m_spawnrate * Timedelta ),
|
m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity ),
|
||||||
m_particles.capacity() ) );
|
m_particles.capacity() ) );
|
||||||
// update spawned particles
|
// update spawned particles
|
||||||
for( auto particleiterator { std::begin( m_particles ) }; particleiterator != std::end( m_particles ); ++particleiterator ) {
|
for( auto particleiterator { std::begin( m_particles ) }; particleiterator != std::end( m_particles ); ++particleiterator ) {
|
||||||
@@ -276,13 +276,14 @@ smoke_source::initialize( smoke_particle &Particle ) {
|
|||||||
|
|
||||||
if( m_ownertype == owner_type::vehicle ) {
|
if( m_ownertype == owner_type::vehicle ) {
|
||||||
Particle.opacity *= m_owner.vehicle->MoverParameters->dizel_fill;
|
Particle.opacity *= m_owner.vehicle->MoverParameters->dizel_fill;
|
||||||
|
auto const enginerevolutionsfactor { 1.5f }; // high engine revolutions increase initial particle velocity
|
||||||
switch( m_owner.vehicle->MoverParameters->EngineType ) {
|
switch( m_owner.vehicle->MoverParameters->EngineType ) {
|
||||||
case TEngineType::DieselElectric: {
|
case TEngineType::DieselElectric: {
|
||||||
Particle.velocity *= 1.0 + m_owner.vehicle->MoverParameters->enrot / ( m_owner.vehicle->MoverParameters->DElist[ m_owner.vehicle->MoverParameters->MainCtrlPosNo ].RPM / 60.0 );
|
Particle.velocity *= 1.0 + enginerevolutionsfactor * m_owner.vehicle->MoverParameters->enrot / ( m_owner.vehicle->MoverParameters->DElist[ m_owner.vehicle->MoverParameters->MainCtrlPosNo ].RPM / 60.0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TEngineType::DieselEngine: {
|
case TEngineType::DieselEngine: {
|
||||||
Particle.velocity *= 1.0 + m_owner.vehicle->MoverParameters->enrot / m_owner.vehicle->MoverParameters->nmax;
|
Particle.velocity *= 1.0 + enginerevolutionsfactor * m_owner.vehicle->MoverParameters->enrot / m_owner.vehicle->MoverParameters->nmax;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -398,7 +399,9 @@ particle_manager::find( std::string const &Template ) {
|
|||||||
// ... and if it fails try to add the template to the database from a data file
|
// ... and if it fails try to add the template to the database from a data file
|
||||||
smoke_source source;
|
smoke_source source;
|
||||||
if( source.deserialize( cParser( templatepath + templatename + ".txt", cParser::buffer_FILE ) ) ) {
|
if( source.deserialize( cParser( templatepath + templatename + ".txt", cParser::buffer_FILE ) ) ) {
|
||||||
// if deserialization didn't fail cache the source as template for future instances
|
// if deserialization didn't fail finish source setup...
|
||||||
|
source.m_opacitymodifier.bind( &Global.SmokeFidelity );
|
||||||
|
// ...then cache the source as template for future instances
|
||||||
m_sourcetemplates.emplace( templatename, source );
|
m_sourcetemplates.emplace( templatename, source );
|
||||||
// should be 'safe enough' to return lookup result directly afterwards
|
// should be 'safe enough' to return lookup result directly afterwards
|
||||||
return &( m_sourcetemplates.find( templatename )->second );
|
return &( m_sourcetemplates.find( templatename )->second );
|
||||||
|
|||||||
15
particles.h
15
particles.h
@@ -48,9 +48,15 @@ public:
|
|||||||
// updates state of provided variable
|
// updates state of provided variable
|
||||||
void
|
void
|
||||||
update( Type_ &Variable, double const Timedelta ) const;
|
update( Type_ &Variable, double const Timedelta ) const;
|
||||||
|
void
|
||||||
|
bind( Type_ const *Modifier ) {
|
||||||
|
m_valuechangemodifier = Modifier; }
|
||||||
Type_ const &
|
Type_ const &
|
||||||
value_change() const {
|
value_change() const {
|
||||||
return m_valuechange; }
|
return (
|
||||||
|
m_valuechangemodifier == nullptr ?
|
||||||
|
m_valuechange :
|
||||||
|
m_valuechange / *( m_valuechangemodifier ) ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//types
|
//types
|
||||||
@@ -59,6 +65,7 @@ private:
|
|||||||
// Type_ m_intialvalue { Type_( 0 ) }; // meters per second; velocity applied to freshly spawned particles
|
// Type_ m_intialvalue { Type_( 0 ) }; // meters per second; velocity applied to freshly spawned particles
|
||||||
Type_ m_valuechange { Type_( 0 ) }; // meters per second; change applied to initial velocity
|
Type_ m_valuechange { Type_( 0 ) }; // meters per second; change applied to initial velocity
|
||||||
Type_ m_valuelimits[ 2 ] { Type_( std::numeric_limits<Type_>::lowest() ), Type_( std::numeric_limits<Type_>::max() ) };
|
Type_ m_valuelimits[ 2 ] { Type_( std::numeric_limits<Type_>::lowest() ), Type_( std::numeric_limits<Type_>::max() ) };
|
||||||
|
Type_ const *m_valuechangemodifier{ nullptr }; // optional modifier applied to value change
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -203,7 +210,11 @@ void
|
|||||||
fixedstep_modifier<Type_>::update( Type_ &Variable, double const Timedelta ) const {
|
fixedstep_modifier<Type_>::update( Type_ &Variable, double const Timedelta ) const {
|
||||||
// HACK: float cast to avoid vec3 and double mismatch
|
// HACK: float cast to avoid vec3 and double mismatch
|
||||||
// TBD, TODO: replace with vector types specialization
|
// TBD, TODO: replace with vector types specialization
|
||||||
Variable += ( m_valuechange * static_cast<float>( Timedelta ) );
|
auto const valuechange { (
|
||||||
|
m_valuechangemodifier == nullptr ?
|
||||||
|
m_valuechange :
|
||||||
|
m_valuechange / *( m_valuechangemodifier ) ) };
|
||||||
|
Variable += ( valuechange * static_cast<float>( Timedelta ) );
|
||||||
// clamp down to allowed value range
|
// clamp down to allowed value range
|
||||||
Variable = glm::max( Variable, m_valuelimits[ value_limit::min ] );
|
Variable = glm::max( Variable, m_valuelimits[ value_limit::min ] );
|
||||||
Variable = glm::min( Variable, m_valuelimits[ value_limit::max ] );
|
Variable = glm::min( Variable, m_valuelimits[ value_limit::max ] );
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ void
|
|||||||
opengl_particles::update( opengl_camera const &Camera ) {
|
opengl_particles::update( opengl_camera const &Camera ) {
|
||||||
|
|
||||||
m_particlevertices.clear();
|
m_particlevertices.clear();
|
||||||
|
|
||||||
|
if( false == Global.Smoke ) { return; }
|
||||||
|
|
||||||
// build a list of visible smoke sources
|
// build a list of visible smoke sources
|
||||||
// NOTE: arranged by distance to camera, if we ever need sorting and/or total amount cap-based culling
|
// NOTE: arranged by distance to camera, if we ever need sorting and/or total amount cap-based culling
|
||||||
std::multimap<float, smoke_source const &> sources;
|
std::multimap<float, smoke_source const &> sources;
|
||||||
@@ -213,6 +216,7 @@ opengl_particles::update( opengl_camera const &Camera ) {
|
|||||||
void
|
void
|
||||||
opengl_particles::render( int const Textureunit ) {
|
opengl_particles::render( int const Textureunit ) {
|
||||||
|
|
||||||
|
if( false == Global.Smoke ) { return; }
|
||||||
if( m_buffercapacity == 0 ) { return; }
|
if( m_buffercapacity == 0 ) { return; }
|
||||||
if( m_particlevertices.empty() ) { return; }
|
if( m_particlevertices.empty() ) { return; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user