16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Fog, skydome and other environment tweaks

This commit is contained in:
Jano211
2023-08-11 21:19:52 +02:00
committed by Hirek
parent 92958a28d2
commit e228366c42
6 changed files with 55 additions and 25 deletions

View File

@@ -388,11 +388,8 @@ global_settings::ConfigParse(cParser &Parser) {
// selected device for audio renderer // selected device for audio renderer
Parser.getTokens(); Parser.getTokens();
Parser >> AirTemperature; Parser >> AirTemperature;
if (false == DebugModeFlag)
{
AirTemperature = clamp(AirTemperature, -15.f, 45.f); AirTemperature = clamp(AirTemperature, -15.f, 45.f);
} }
}
else if (token == "scalespeculars") else if (token == "scalespeculars")
{ {
// whether strength of specular highlights should be adjusted (generally needed for // whether strength of specular highlights should be adjusted (generally needed for

View File

@@ -86,6 +86,7 @@ struct global_settings {
float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere
glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f }; glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f };
float fFogEnd{ 7500 }; float fFogEnd{ 7500 };
float fTurbidity{ 128 };
std::string Season{}; // season of the year, based on simulation date std::string Season{}; // season of the year, based on simulation date
std::string Weather{ "cloudy:" }; // current weather std::string Weather{ "cloudy:" }; // current weather
std::string Period{}; // time of the day, based on sun position std::string Period{}; // time of the day, based on sun position

View File

@@ -659,11 +659,25 @@ debug_panel::render_section_scenario() {
{ {
auto fogrange = std::log( Global.fFogEnd ); auto fogrange = std::log( Global.fFogEnd );
if( ImGui::SliderFloat( if( ImGui::SliderFloat(
( to_string( std::exp( fogrange ), 0, 5 ) + " m###fogend" ).c_str(), &fogrange, std::log( 10.0f ), std::log( 25000.0f ), "Fog distance" ) ) { ( to_string( std::exp( fogrange ), 0, 5 ) + " m###fogend" ).c_str(), &fogrange, std::log( 10.0f ), std::log( 50000.0f ), "Fog distance" ) ) {
command_relay relay; command_relay relay;
relay.post( relay.post(
user_command::setweather, user_command::setweather,
clamp( std::exp( fogrange ), 10.0f, 25000.0f ), clamp( std::exp( fogrange ), 10.0f, 50000.0f ),
Global.Overcast,
GLFW_PRESS, 0 );
}
}
{
auto Airtemperature = Global.AirTemperature;
if (ImGui::SliderFloat(
(to_string(Airtemperature, 1) + " deg C###Airtemperature").c_str(),
&Airtemperature, -35.0f, 40.0f, "Air Temperature"))
{
command_relay relay;
relay.post(
user_command::settemperature,
clamp(Airtemperature, -35.0f, 40.0f),
Global.Overcast, Global.Overcast,
GLFW_PRESS, 0 ); GLFW_PRESS, 0 );
} }
@@ -1288,7 +1302,7 @@ debug_panel::update_section_scenario( std::vector<text_line> &Output ) {
Output.emplace_back( textline, Global.UITextColor ); Output.emplace_back( textline, Global.UITextColor );
// current luminance level // current luminance level
textline = "Light level: " + to_string( Global.fLuminance, 3 ) + ( Global.FakeLight ? "(*)" : "" ); textline = "Light level: " + to_string( Global.fLuminance, 3 ) + ( Global.FakeLight ? "(*)" : "" )+ to_string(Global.SunAngle,2);
textline += textline +=
"\nWind: azimuth " "\nWind: azimuth "
+ to_string( simulation::Environment.wind_azimuth(), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód + to_string( simulation::Environment.wind_azimuth(), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód

View File

@@ -339,6 +339,8 @@ void state_manager::process_commands() {
if (commanddata.command == user_command::settemperature) { if (commanddata.command == user_command::settemperature) {
Global.AirTemperature = commanddata.param1; Global.AirTemperature = commanddata.param1;
Global.Overcast = commanddata.param2;
simulation::Environment.compute_weather();
} }
if (commanddata.command == user_command::insertmodel) { if (commanddata.command == user_command::insertmodel) {

View File

@@ -66,9 +66,23 @@ world_environment::compute_weather() {
Global.Overcast <= 0.50 ? "scattered:" : Global.Overcast <= 0.50 ? "scattered:" :
Global.Overcast <= 0.90 ? "broken:" : Global.Overcast <= 0.90 ? "broken:" :
Global.Overcast <= 1.00 ? "overcast:" : Global.Overcast <= 1.00 ? "overcast:" :
( Global.Season != "winter:" ?
"rain:" : (Global.AirTemperature > 1 ? "rain:" :
"snow:" ) ); "snow:" ) );
Global.fTurbidity = (
Global.Overcast <= 0.10 ? 3 :
Global.Overcast <= 0.20 ? 4 :
Global.Overcast <= 0.30 ? 5 :
Global.Overcast <= 0.40 ? 5 :
Global.Overcast <= 0.50 ? 5 :
Global.Overcast <= 0.60 ? 5 :
Global.Overcast <= 0.70 ? 6 :
Global.Overcast <= 0.80 ? 7 :
Global.Overcast <= 0.90 ? 8 :
Global.Overcast > 0.90 ? 9 :
9
);
} }
void void
@@ -120,7 +134,9 @@ world_environment::update() {
float keylightintensity; float keylightintensity;
glm::vec3 keylightcolor; glm::vec3 keylightcolor;
if( moonlightlevel > sunlightlevel ) { Global.SunAngle = m_sun.getAngle();
if ((moonlightlevel > sunlightlevel) && (Global.SunAngle <(-20)))
{
// rare situations when the moon is brighter than the sun, typically at night // rare situations when the moon is brighter than the sun, typically at night
Global.SunAngle = m_moon.getAngle(); Global.SunAngle = m_moon.getAngle();
Global.DayLight.position = m_moon.getDirection(); Global.DayLight.position = m_moon.getDirection();
@@ -139,10 +155,10 @@ world_environment::update() {
keylightintensity = sunlightlevel; keylightintensity = sunlightlevel;
m_lightintensity = 1.0f; m_lightintensity = 1.0f;
// include 'golden hour' effect in twilight lighting // include 'golden hour' effect in twilight lighting
float const duskfactor = 1.0f - clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f; float const duskfactor = 1.25f - clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f;
keylightcolor = interpolate( keylightcolor = interpolate(
glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ), glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
glm::vec3( 235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f ), glm::vec3( 235.0f / 255.0f, 120.0f / 255.0f, 36.0f / 255.0f ),
duskfactor ); duskfactor );
} }
// ...retrieve current sky colour and brightness... // ...retrieve current sky colour and brightness...
@@ -174,9 +190,9 @@ world_environment::update() {
// update the fog. setting it to match the average colour of the sky dome is cheap // update the fog. setting it to match the average colour of the sky dome is cheap
// but quite effective way to make the distant items blend with background better // but quite effective way to make the distant items blend with background better
Global.FogColor = Global.FogColor = ((m_skydome.GetAverageHorizonColor()) * keylightcolor) *
interpolate( m_skydome.GetAverageColor(), m_skydome.GetAverageHorizonColor(), 0.25f ) clamp<float>(Global.fLuminance, 0.0f, 1.f);
* clamp<float>( Global.fLuminance, 0.25f, 1.f );
// weather-related simulation factors // weather-related simulation factors
Global.FrictionWeatherFactor = ( Global.FrictionWeatherFactor = (

View File

@@ -10,8 +10,8 @@
// by A. J. Preetham Peter Shirley Brian Smits (University of Utah) // by A. J. Preetham Peter Shirley Brian Smits (University of Utah)
float CSkyDome::m_distributionluminance[ 5 ][ 2 ] = { // Perez distributions float CSkyDome::m_distributionluminance[ 5 ][ 2 ] = { // Perez distributions
{ 0.17872f , -1.46303f }, // a = darkening or brightening of the horizon { 0.17872f , -1.66303f }, // a = darkening or brightening of the horizon
{ -0.35540f , 0.42749f }, // b = luminance gradient near the horizon, { -0.35540f , 0.42750f }, // b = luminance gradient near the horizon,
{ -0.02266f , 5.32505f }, // c = relative intensity of the circumsolar region { -0.02266f , 5.32505f }, // c = relative intensity of the circumsolar region
{ 0.12064f , -2.57705f }, // d = width of the circumsolar region { 0.12064f , -2.57705f }, // d = width of the circumsolar region
{ -0.06696f , 0.37027f } // e = relative backscattered light { -0.06696f , 0.37027f } // e = relative backscattered light
@@ -48,8 +48,8 @@ CSkyDome::CSkyDome (int const Tesselation) :
m_tesselation( Tesselation ) { m_tesselation( Tesselation ) {
// SetSunPosition( Math3D::vector3(75.0f, 0.0f, 0.0f) ); // SetSunPosition( Math3D::vector3(75.0f, 0.0f, 0.0f) );
SetTurbidity( 3.0f ); SetTurbidity( Global.fTurbidity );
SetExposure( true, 20.0f ); SetExposure( true, 10.0f );
SetOvercastFactor( 0.05f ); SetOvercastFactor( 0.05f );
Generate(); Generate();
} }
@@ -109,7 +109,7 @@ void CSkyDome::Generate() {
} }
void CSkyDome::Update( glm::vec3 const &Sun ) { void CSkyDome::Update( glm::vec3 const &Sun ) {
SetTurbidity(Global.fTurbidity);
if( true == SetSunPosition( Sun ) ) { if( true == SetSunPosition( Sun ) ) {
// build colors if there's a change in sun position // build colors if there's a change in sun position
RebuildColors(); RebuildColors();
@@ -134,7 +134,7 @@ bool CSkyDome::SetSunPosition( glm::vec3 const &Direction ) {
void CSkyDome::SetTurbidity( float const Turbidity ) { void CSkyDome::SetTurbidity( float const Turbidity ) {
m_turbidity = clamp( Turbidity, 1.f, 4.f ); m_turbidity = clamp( Turbidity, 1.f, 128.f );
} }
void CSkyDome::SetExposure( bool const Linearexposure, float const Expfactor ) { void CSkyDome::SetExposure( bool const Linearexposure, float const Expfactor ) {
@@ -296,20 +296,20 @@ void CSkyDome::RebuildColors() {
color.y = 0.65f * color.z; color.y = 0.65f * color.z;
} }
// simple gradient, darkening towards the top // simple gradient, darkening towards the top
color *= clamp( ( 1.25f - vertex.y ), 0.f, 1.f ); color *= clamp( ( 1.0f - vertex.y ), 0.f, 1.f );
// color *= ( 1.25f - vertex.y ); //color *= ( 0.25f - vertex.y );
// gamma correction // gamma correction
color = glm::pow( color, gammacorrection ); color = glm::pow( color, gammacorrection );
m_colours[ i ] = color; m_colours[ i ] = color;
averagecolor += color; averagecolor += color;
if( ( m_vertices.size() - i ) <= ( m_tesselation * 3 + 3 ) ) { if( ( m_vertices.size() - i ) <= ( m_tesselation * 10 + 10 ) ) {
// calculate horizon colour from the bottom band of tris // calculate horizon colour from the bottom band of tris
averagehorizoncolor += color; averagehorizoncolor += color;
} }
} }
m_averagecolour = glm::max( glm::vec3(), averagecolor / static_cast<float>( m_vertices.size() ) ); m_averagecolour = glm::max( glm::vec3(), averagecolor / static_cast<float>( m_vertices.size() ) );
m_averagehorizoncolour = glm::max( glm::vec3(), averagehorizoncolor / static_cast<float>( m_tesselation * 3 + 3 ) ); m_averagehorizoncolour = glm::max( glm::vec3(), averagehorizoncolor / static_cast<float>( m_tesselation * 10 + 10 ) );
m_dirty = true; m_dirty = true;
} }