mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Fog, skydome and other environment tweaks
This commit is contained in:
@@ -388,10 +388,7 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
// selected device for audio renderer
|
||||
Parser.getTokens();
|
||||
Parser >> AirTemperature;
|
||||
if (false == DebugModeFlag)
|
||||
{
|
||||
AirTemperature = clamp(AirTemperature, -15.f, 45.f);
|
||||
}
|
||||
AirTemperature = clamp(AirTemperature, -15.f, 45.f);
|
||||
}
|
||||
else if (token == "scalespeculars")
|
||||
{
|
||||
|
||||
@@ -86,6 +86,7 @@ struct global_settings {
|
||||
float Overcast{ 0.1f }; // NOTE: all this weather stuff should be moved elsewhere
|
||||
glm::vec3 FogColor = { 0.6f, 0.7f, 0.8f };
|
||||
float fFogEnd{ 7500 };
|
||||
float fTurbidity{ 128 };
|
||||
std::string Season{}; // season of the year, based on simulation date
|
||||
std::string Weather{ "cloudy:" }; // current weather
|
||||
std::string Period{}; // time of the day, based on sun position
|
||||
|
||||
@@ -659,15 +659,29 @@ debug_panel::render_section_scenario() {
|
||||
{
|
||||
auto fogrange = std::log( Global.fFogEnd );
|
||||
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;
|
||||
relay.post(
|
||||
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,
|
||||
GLFW_PRESS, 0 );
|
||||
}
|
||||
}
|
||||
// cloud cover slider
|
||||
{
|
||||
if( ImGui::SliderFloat(
|
||||
@@ -1288,7 +1302,7 @@ debug_panel::update_section_scenario( std::vector<text_line> &Output ) {
|
||||
|
||||
Output.emplace_back( textline, Global.UITextColor );
|
||||
// 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 +=
|
||||
"\nWind: azimuth "
|
||||
+ to_string( simulation::Environment.wind_azimuth(), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód
|
||||
|
||||
@@ -339,6 +339,8 @@ void state_manager::process_commands() {
|
||||
|
||||
if (commanddata.command == user_command::settemperature) {
|
||||
Global.AirTemperature = commanddata.param1;
|
||||
Global.Overcast = commanddata.param2;
|
||||
simulation::Environment.compute_weather();
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::insertmodel) {
|
||||
|
||||
@@ -66,9 +66,23 @@ world_environment::compute_weather() {
|
||||
Global.Overcast <= 0.50 ? "scattered:" :
|
||||
Global.Overcast <= 0.90 ? "broken:" :
|
||||
Global.Overcast <= 1.00 ? "overcast:" :
|
||||
( Global.Season != "winter:" ?
|
||||
"rain:" :
|
||||
|
||||
(Global.AirTemperature > 1 ? "rain:" :
|
||||
"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
|
||||
@@ -120,7 +134,9 @@ world_environment::update() {
|
||||
|
||||
float keylightintensity;
|
||||
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
|
||||
Global.SunAngle = m_moon.getAngle();
|
||||
Global.DayLight.position = m_moon.getDirection();
|
||||
@@ -139,10 +155,10 @@ world_environment::update() {
|
||||
keylightintensity = sunlightlevel;
|
||||
m_lightintensity = 1.0f;
|
||||
// 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(
|
||||
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 );
|
||||
}
|
||||
// ...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
|
||||
// but quite effective way to make the distant items blend with background better
|
||||
Global.FogColor =
|
||||
interpolate( m_skydome.GetAverageColor(), m_skydome.GetAverageHorizonColor(), 0.25f )
|
||||
* clamp<float>( Global.fLuminance, 0.25f, 1.f );
|
||||
Global.FogColor = ((m_skydome.GetAverageHorizonColor()) * keylightcolor) *
|
||||
clamp<float>(Global.fLuminance, 0.0f, 1.f);
|
||||
|
||||
|
||||
// weather-related simulation factors
|
||||
Global.FrictionWeatherFactor = (
|
||||
|
||||
20
skydome.cpp
20
skydome.cpp
@@ -10,8 +10,8 @@
|
||||
// by A. J. Preetham Peter Shirley Brian Smits (University of Utah)
|
||||
|
||||
float CSkyDome::m_distributionluminance[ 5 ][ 2 ] = { // Perez distributions
|
||||
{ 0.17872f , -1.46303f }, // a = darkening or brightening of the horizon
|
||||
{ -0.35540f , 0.42749f }, // b = luminance gradient near the horizon,
|
||||
{ 0.17872f , -1.66303f }, // a = darkening or brightening of the horizon
|
||||
{ -0.35540f , 0.42750f }, // b = luminance gradient near the horizon,
|
||||
{ -0.02266f , 5.32505f }, // c = relative intensity of the circumsolar region
|
||||
{ 0.12064f , -2.57705f }, // d = width of the circumsolar region
|
||||
{ -0.06696f , 0.37027f } // e = relative backscattered light
|
||||
@@ -48,8 +48,8 @@ CSkyDome::CSkyDome (int const Tesselation) :
|
||||
m_tesselation( Tesselation ) {
|
||||
|
||||
// SetSunPosition( Math3D::vector3(75.0f, 0.0f, 0.0f) );
|
||||
SetTurbidity( 3.0f );
|
||||
SetExposure( true, 20.0f );
|
||||
SetTurbidity( Global.fTurbidity );
|
||||
SetExposure( true, 10.0f );
|
||||
SetOvercastFactor( 0.05f );
|
||||
Generate();
|
||||
}
|
||||
@@ -109,7 +109,7 @@ void CSkyDome::Generate() {
|
||||
}
|
||||
|
||||
void CSkyDome::Update( glm::vec3 const &Sun ) {
|
||||
|
||||
SetTurbidity(Global.fTurbidity);
|
||||
if( true == SetSunPosition( Sun ) ) {
|
||||
// build colors if there's a change in sun position
|
||||
RebuildColors();
|
||||
@@ -134,7 +134,7 @@ bool CSkyDome::SetSunPosition( glm::vec3 const &Direction ) {
|
||||
|
||||
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 ) {
|
||||
@@ -296,20 +296,20 @@ void CSkyDome::RebuildColors() {
|
||||
color.y = 0.65f * color.z;
|
||||
}
|
||||
// simple gradient, darkening towards the top
|
||||
color *= clamp( ( 1.25f - vertex.y ), 0.f, 1.f );
|
||||
// color *= ( 1.25f - vertex.y );
|
||||
color *= clamp( ( 1.0f - vertex.y ), 0.f, 1.f );
|
||||
//color *= ( 0.25f - vertex.y );
|
||||
// gamma correction
|
||||
color = glm::pow( color, gammacorrection );
|
||||
m_colours[ i ] = 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
|
||||
averagehorizoncolor += color;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user