17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-04 01:52:05 +01:00

Add sky light, physical atmosphere, auto exposure and bloom to the GL 4.6 renderer

This commit is contained in:
2026-10-15 22:16:41 +02:00
parent ea0dba6dae
commit ce725c3d62
37 changed files with 2342 additions and 32 deletions

View File

@@ -1534,6 +1534,10 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token
Parser >> gfx_shadow_rank_cutoff;
gfx_shadow_rank_cutoff = std::clamp(gfx_shadow_rank_cutoff, 1, 3);
}
else if (ConfigParse_gfx_sky(Parser, Token))
{
// parsed
}
else
{
tokenparsed = false;
@@ -1542,6 +1546,43 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token
return tokenparsed;
}
bool
global_settings::ConfigParse_gfx_sky( cParser &Parser, std::string_view const Token ) {
// switches take yes/no (or true/false, 1/0), scales take a number. a missing entry keeps the default
auto const readswitch = [&]( bool &Value ) {
Parser.getTokens( 1 );
Parser >> Value; };
auto const readvalue = [&]( float &Value, float const Min, float const Max ) {
Parser.getTokens( 1 );
Parser >> Value;
Value = std::clamp( Value, Min, Max ); };
if( Token == "gfx.ambient.sh" ) { readswitch( gfx_ambient_sh ); }
else if( Token == "gfx.ambient.sh.strength" ) { readvalue( gfx_ambient_sh_strength, 0.f, 2.f ); }
else if( Token == "gfx.ambient.groundalbedo" ) { readvalue( gfx_ambient_groundalbedo, 0.f, 1.f ); }
else if( Token == "gfx.envmap.ggx" ) { readswitch( gfx_envmap_ggx ); }
else if( Token == "gfx.atmosphere" ) { readswitch( gfx_atmosphere ); }
else if( Token == "gfx.atmosphere.sky" ) { readvalue( gfx_atmosphere_sky, 0.f, 16.f ); }
else if( Token == "gfx.atmosphere.ambient" ) { readvalue( gfx_atmosphere_ambient, 0.f, 16.f ); }
else if( Token == "gfx.atmosphere.sun" ) { readvalue( gfx_atmosphere_sun, 0.f, 16.f ); }
else if( Token == "gfx.atmosphere.haze" ) { readvalue( gfx_atmosphere_haze, 0.f, 32.f ); }
else if( Token == "gfx.atmosphere.altitude" ) { readvalue( gfx_atmosphere_altitude, 0.f, 9000.f ); }
else if( Token == "gfx.postfx.autoexposure" ) { readswitch( gfx_postfx_autoexposure ); }
else if( Token == "gfx.postfx.autoexposure.key" ) { readvalue( gfx_postfx_autoexposure_key, 0.001f, 100.f ); }
else if( Token == "gfx.postfx.autoexposure.min" ) { readvalue( gfx_postfx_autoexposure_min, -16.f, 0.f ); }
else if( Token == "gfx.postfx.autoexposure.max" ) { readvalue( gfx_postfx_autoexposure_max, 0.f, 16.f ); }
else if( Token == "gfx.postfx.autoexposure.speed.dark" ) { readvalue( gfx_postfx_autoexposure_speed_dark, 0.01f, 100.f ); }
else if( Token == "gfx.postfx.autoexposure.speed.bright" ) { readvalue( gfx_postfx_autoexposure_speed_bright, 0.01f, 100.f ); }
else if( Token == "gfx.postfx.autoexposure.compensation" ) { readvalue( gfx_postfx_autoexposure_compensation, -16.f, 16.f ); }
else if( Token == "gfx.postfx.bloom" ) { readswitch( gfx_postfx_bloom ); }
else if( Token == "gfx.postfx.bloom.intensity" ) { readvalue( gfx_postfx_bloom_intensity, 0.f, 1.f ); }
else if( Token == "gfx.postfx.bloom.threshold" ) { readvalue( gfx_postfx_bloom_threshold, 0.f, 1000.f ); }
else { return false; }
return true;
}
void
global_settings::export_as_text( std::ostream &Output ) const {
@@ -1778,6 +1819,26 @@ global_settings::export_as_text( std::ostream &Output ) const {
export_as_text( Output, "gfx.shadergamma", gfx_shadergamma );
export_as_text( Output, "gfx.shadow.angle.min", gfx_shadow_angle_min );
export_as_text( Output, "gfx.shadow.rank.cutoff", gfx_shadow_rank_cutoff );
export_as_text( Output, "gfx.ambient.sh", gfx_ambient_sh );
export_as_text( Output, "gfx.ambient.sh.strength", gfx_ambient_sh_strength );
export_as_text( Output, "gfx.ambient.groundalbedo", gfx_ambient_groundalbedo );
export_as_text( Output, "gfx.envmap.ggx", gfx_envmap_ggx );
export_as_text( Output, "gfx.atmosphere", gfx_atmosphere );
export_as_text( Output, "gfx.atmosphere.sky", gfx_atmosphere_sky );
export_as_text( Output, "gfx.atmosphere.ambient", gfx_atmosphere_ambient );
export_as_text( Output, "gfx.atmosphere.sun", gfx_atmosphere_sun );
export_as_text( Output, "gfx.atmosphere.haze", gfx_atmosphere_haze );
export_as_text( Output, "gfx.atmosphere.altitude", gfx_atmosphere_altitude );
export_as_text( Output, "gfx.postfx.autoexposure", gfx_postfx_autoexposure );
export_as_text( Output, "gfx.postfx.autoexposure.key", gfx_postfx_autoexposure_key );
export_as_text( Output, "gfx.postfx.autoexposure.min", gfx_postfx_autoexposure_min );
export_as_text( Output, "gfx.postfx.autoexposure.max", gfx_postfx_autoexposure_max );
export_as_text( Output, "gfx.postfx.autoexposure.speed.dark", gfx_postfx_autoexposure_speed_dark );
export_as_text( Output, "gfx.postfx.autoexposure.speed.bright", gfx_postfx_autoexposure_speed_bright );
export_as_text( Output, "gfx.postfx.autoexposure.compensation", gfx_postfx_autoexposure_compensation );
export_as_text( Output, "gfx.postfx.bloom", gfx_postfx_bloom );
export_as_text( Output, "gfx.postfx.bloom.intensity", gfx_postfx_bloom_intensity );
export_as_text( Output, "gfx.postfx.bloom.threshold", gfx_postfx_bloom_threshold );
export_as_text( Output, "python.enabled", python_enabled );
export_as_text( Output, "python.threadedupload", python_threadedupload );
export_as_text( Output, "python.uploadmain", python_uploadmain );

View File

@@ -302,6 +302,29 @@ struct global_settings {
float gfx_shadow_angle_min { -0.2f };
int gfx_shadow_rank_cutoff { 3 };
// sky light and exposure of the opengl 4.6 renderer. the switches can also be changed at run time in the debug window
// "Sky and exposure"; the scales are multipliers of the calibrated defaults (1 = as calibrated)
bool gfx_ambient_sh { true }; // the ambient light depends on where a surface faces: the sky above, the ground below
float gfx_ambient_sh_strength { 1.f }; // 0 = uniform ambient light as before, 1 = full directional difference
float gfx_ambient_groundalbedo { 0.1f }; // how much light the ground below the horizon gives back
bool gfx_envmap_ggx { true }; // rough reflections from the environment map prefiltered with the GGX lobe
bool gfx_atmosphere { true }; // sky, sun, ambient light and fog colour from the physical atmosphere (Hillaire 2020)
float gfx_atmosphere_sky { 1.f }; // brightness of the drawn sky and of the fog
float gfx_atmosphere_ambient { 1.f }; // brightness of the ambient light
float gfx_atmosphere_sun { 1.f }; // brightness of the sunlight
float gfx_atmosphere_haze { 1.f }; // amount of aerosols (mie scattering) on a clear day; grows with the overcast
float gfx_atmosphere_altitude { 200.f }; // height of the scenery above the sea level, in metres
bool gfx_postfx_autoexposure { true }; // the exposure follows the brightness of the image, within limits
float gfx_postfx_autoexposure_key { 0.3f }; // average luminance of the image the exposure is set for
float gfx_postfx_autoexposure_min { -1.f }; // lowest exposure correction, EV (darkening of bright images)
float gfx_postfx_autoexposure_max { 0.5f }; // highest exposure correction, EV (brightening of dark images, tunnels)
float gfx_postfx_autoexposure_speed_dark { 1.f }; // rate of adaptation to a darker image, 1/s
float gfx_postfx_autoexposure_speed_bright { 3.f }; // rate of adaptation to a brighter image, 1/s
float gfx_postfx_autoexposure_compensation { 0.f }; // fixed exposure correction, EV, applied with and without the adaptation
bool gfx_postfx_bloom { true }; // glow around bright parts of the image
float gfx_postfx_bloom_intensity { 0.04f }; // share of the blurred image in the result
float gfx_postfx_bloom_threshold { 0.f }; // luminance below which nothing glows, 0 = everything contributes
float ui_fontsize = 13.0f;
float ui_scale = 1.0f;
bool ui_viewports = true; // panels of the ui can be dragged out of the simulator window, into windows of their own
@@ -375,6 +398,8 @@ struct global_settings {
bool ConfigParseHardware(cParser& Parser, const std::string& token);
bool ConfigParseDebug(cParser& Parser, const std::string& token);
bool ConfigParse_gfx( cParser &parser, std::string_view const Token );
// sky light and exposure switches of the opengl 4.6 renderer (gfx.ambient.*, gfx.envmap.ggx, gfx.atmosphere*, gfx.postfx.autoexposure*, gfx.postfx.bloom*)
bool ConfigParse_gfx_sky( cParser &parser, std::string_view const Token );
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;