18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

fix(sky): the legacy renderer gets the sky, ambient and fog of 26.05 again (#415)

* fix(sky): the legacy renderer gets the sky, ambient and fog of 26.05 again

The colours of the sky dome were made for the full renderer, which
tonemaps them and draws to an sRGB framebuffer: the sRGB matrix, the
gamma put on the brightness, a lighter gradient and a band of light
at the horizon (40c21bd4, b46c8c76, 8df81eb4), and the fog no longer
dimmed by the diffuse level (#229). The legacy and simple renderers draw
these colours as they are, and the ambient light and the fog are taken
from them, so all three differed from 26.05 there.

With Global.LegacyRenderer the dome is computed as in 26.05: the Adobe
RGB matrix, the brightness knee at 0.85, the sky tone saturated as the
colour, the plain gradient and the gamma of 0.45 by day at the end; the
fog is lit by the key light at its diffuse level. The full renderer is
unchanged. The turbidity under overcast is a separate fix (#410).

* fix(test): a test run takes the legacy and the simple renderer flag off with the renderer

From the review of #415: apply_test_mode_settings() sets the null renderer
but left Global.LegacyRenderer and Global.BasicRenderer as the gfxrenderer
line of eu07.ini made them. With this PR the legacy flag picks the colours
of the sky dome, and their average is the light level the scenery lamps,
the AI's compartment lights and Python's light_level go by. The same --test
run on a machine with "gfxrenderer legacy" and on one with the default
renderer computed different skies and could switch those lights at other
times. A test run now always takes the sky of the full renderer, as on
master. The context of a test run doesn't depend on the flag (it asks for
none in particular), and its multisampling is off, so nothing else changes.

---------

Co-authored-by: maj00r <maj00r@host>
This commit is contained in:
maj00r
2026-11-24 19:28:02 +01:00
committed by GitHub
parent e0b2bdfb7f
commit 767bcb4682
3 changed files with 54 additions and 10 deletions

View File

@@ -5,6 +5,27 @@
#include "simulation/simulationenvironment.h"
#include "utilities/Globals.h"
namespace {
// XYZ to Adobe RGB, as the sky was converted up to 26.05. the legacy renderer still gets its sky this way:
// it draws the colours of the dome as they are, with no tonemapping of its own
glm::vec3
xyz_to_adobe_rgb( glm::vec3 const &XYZ ) {
// M^-1 for Adobe RGB from http://www.brucelindbloom.com/Eqn_RGB_XYZ_Matrix.html
std::array<glm::vec3, 3> const mi{
glm::vec3{ 2.041369f, -0.969266f, 0.0134474f },
glm::vec3{ -0.5649464f, 1.8760108f, -0.1183897f },
glm::vec3{ -0.3446944f, 0.041556f, 1.0154096f } };
return glm::vec3{
XYZ.x * mi[ 0 ].x + XYZ.y * mi[ 1 ].x + XYZ.z * mi[ 2 ].x,
XYZ.x * mi[ 0 ].y + XYZ.y * mi[ 1 ].y + XYZ.z * mi[ 2 ].y,
XYZ.x * mi[ 0 ].z + XYZ.y * mi[ 1 ].z + XYZ.z * mi[ 2 ].z };
}
} // namespace
// sky gradient based on "A practical analytic model for daylight"
// by A. J. Preetham Peter Shirley Brian Smits (University of Utah)
@@ -185,6 +206,11 @@ void CSkyDome::RebuildColors() {
float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
auto gammacorrection = glm::mix( glm::vec3( 1.0f ), glm::vec3( 0.45f ), twilightfactor );
// the legacy renderer has no tonemapping and no srgb framebuffer, so its sky stays as 26.05 made it:
// display-encoded by day (gamma 0.45), with the brightness knee and the plain gradient, and no horizon band.
// the averages taken from these colours give it the ambient light and the fog of 26.05 too
bool const legacy { Global.LegacyRenderer };
auto const legacygammacorrection = glm::mix( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
// get zenith luminance
auto const chi = static_cast<float>(( 4.0f / 9.0f - m_turbidity / 120.0f ) * ( M_PI - 2.0f * m_thetasun ));
@@ -253,7 +279,7 @@ void CSkyDome::RebuildColors() {
float const Z = (1.0f - x - y) / y * Y;
colorconverter = glm::vec3( X, Y, Z );
color = colors::XYZtoRGB( colorconverter );
color = legacy ? xyz_to_adobe_rgb( colorconverter ) : colors::XYZtoRGB( colorconverter );
colorconverter = colors::RGBtoHSV(color);
if ( m_linearexpcontrol ) {
@@ -264,7 +290,12 @@ void CSkyDome::RebuildColors() {
colorconverter.z = 1.0f - std::exp( -m_expfactor * colorconverter.z );
}
colorconverter.z = std::pow( std::max( colorconverter.z, 0.0f ), gammacorrection.x );
if( false == legacy ) {
colorconverter.z = std::pow( std::max( colorconverter.z, 0.0f ), gammacorrection.x );
}
else if( colorconverter.z > 0.85f ) {
colorconverter.z = 0.85f + ( colorconverter.z - 0.85f ) * 0.35f;
}
colorconverter.y = std::clamp( colorconverter.y * Global.m_skysaturationcorrection, 0.0f, 1.0f );
// desaturate sky colour, based on overcast level
@@ -281,7 +312,7 @@ void CSkyDome::RebuildColors() {
// this height-based factor is reduced the farther the sun is up in the sky
float const shiftfactor = std::clamp( std::lerp(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f );
// h = 210 makes for 'typical' sky tone
glm::vec3 const skytonecolor = colors::HSVtoRGB( glm::vec3( 210.0f, 0.5f, colorconverter.z ) );
glm::vec3 const skytonecolor = colors::HSVtoRGB( glm::vec3( 210.0f, legacy ? colorconverter.y : 0.5f, colorconverter.z ) );
color = colors::HSVtoRGB( colorconverter );
color = glm::mix( color, skytonecolor, shiftfactor * Global.m_skyhuecorrection );
@@ -296,14 +327,21 @@ void CSkyDome::RebuildColors() {
color.x = 0.20f * color.z;
color.y = 0.65f * color.z;
}
// simple gradient, darkening towards the top
color *= std::clamp( 1.0f - vertex.y * 0.75f, 0.0f, 1.f );
if( legacy ) {
// simple gradient, darkening towards the top, then the gamma correction
color *= std::clamp( 1.0f - vertex.y, 0.f, 1.f );
color = glm::pow( glm::max( color, glm::vec3( 0.f ) ), legacygammacorrection );
}
else {
// simple gradient, darkening towards the top
color *= std::clamp( 1.0f - vertex.y * 0.75f, 0.0f, 1.f );
float const horizonboost = 1.5f + m_overcast;
float const horizonbandwidth = 0.2f; // boost tapers to 0 by ~11.5 degrees elevation
float const horizonband = std::clamp( 1.0f - vertex.y / horizonbandwidth, 0.0f, 1.0f );
float const horizonboost = 1.5f + m_overcast;
float const horizonbandwidth = 0.2f; // boost tapers to 0 by ~11.5 degrees elevation
float const horizonband = std::clamp( 1.0f - vertex.y / horizonbandwidth, 0.0f, 1.0f );
color *= std::lerp( 1.0, horizonboost, horizonband );
color *= std::lerp( 1.0, horizonboost, horizonband );
}
//color *= ( 0.25f - vertex.y );
m_colours[ i ] = color;

View File

@@ -190,7 +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 = m_skydome.GetAverageHorizonColor() * keylightcolor *
// the legacy renderer keeps the fog of 26.05, lit by the key light at its diffuse level
glm::vec3 const foglightcolor { Global.LegacyRenderer ? keylightcolor * diffuselevel : keylightcolor };
Global.FogColor = m_skydome.GetAverageHorizonColor() * foglightcolor *
std::clamp((float)Global.fLuminance, 0.f, 1.f);

View File

@@ -62,6 +62,10 @@ void apply_test_mode_settings()
Global.local_start_vehicle = "ghostview";
Global.GfxRenderer = "null";
Global.NvRenderer = false;
// the flags of the gfxrenderer line read from the settings go with it: the legacy one picks the colours of the sky,
// and with them the light level the lamps and the AI go by, so a test run would depend on the renderer of the ini
Global.LegacyRenderer = false;
Global.BasicRenderer = false;
Global.bSoundEnabled = false;
Global.python_enabled = false;
Global.bInactivePause = false;