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

Replace interpolate with std::lerp and glm::mix

This commit is contained in:
docentYT
2026-05-02 01:31:38 +02:00
parent 362338ee5e
commit 3628eb0fc3
21 changed files with 108 additions and 116 deletions

View File

@@ -1915,7 +1915,7 @@ bool opengl33_renderer::Render(world_environment *Environment)
auto const fogfactor{std::clamp(Global.fFogEnd / 2000.f, 0.f, 1.f)}; // stronger fog reduces opacity of the celestial bodies
float const duskfactor = 1.0f - std::clamp(std::abs(Environment->m_sun.getAngle()), 0.0f, 12.0f) / 12.0f;
glm::vec3 suncolor = 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), duskfactor);
glm::vec3 suncolor = glm::mix(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), duskfactor);
// sun
{
@@ -1923,7 +1923,7 @@ bool opengl33_renderer::Render(world_environment *Environment)
glm::vec4 color(suncolor.x, suncolor.y, suncolor.z, std::clamp(1.5f - Global.Overcast, 0.f, 1.f) * fogfactor);
auto const sunvector = Environment->m_sun.getDirection();
/*float const size = interpolate( // TODO: expose distance/scale factor from the moon object
/*float const size = std::lerp( // TODO: expose distance/scale factor from the moon object
0.0325f,
0.0275f,
std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );*/
@@ -2000,7 +2000,7 @@ bool opengl33_renderer::Render(world_environment *Environment)
}
/*
float const size = interpolate( // TODO: expose distance/scale factor from the moon object
float const size = std::lerp( // TODO: expose distance/scale factor from the moon object
0.0160f,
0.0135f,
std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );*/
@@ -2044,7 +2044,7 @@ bool opengl33_renderer::Render(world_environment *Environment)
m_sunlight.apply_intensity();
// calculate shadow tone, based on positions of celestial bodies
m_shadowcolor = interpolate(glm::vec4{colors::shadow}, glm::vec4{colors::white}, std::clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f);
m_shadowcolor = glm::mix(glm::vec4{colors::shadow}, glm::vec4{colors::white}, std::clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f);
if ((Environment->m_sun.getAngle() < -18.f) && (Environment->m_moon.getAngle() > 0.f))
{
// turn on moon shadows after nautical twilight, if the moon is actually up
@@ -3715,7 +3715,7 @@ void opengl33_renderer::Render_precipitation()
::glRotated(m_precipitationrotation, 0.0, 1.0, 0.0);
model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW));
model_ubs.param[0] = interpolate(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * std::clamp((float)Global.fLuminance, 0.f, 1.f));
model_ubs.param[0] = glm::mix(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * std::clamp((float)Global.fLuminance, 0.f, 1.f));
model_ubs.param[1].x = simulation::Environment.m_precipitation.get_textureoffset();
model_ubo->update(model_ubs);
@@ -4161,7 +4161,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
// NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh
// TODO: separate instance data from reusable geometry
auto const &modelview = OpenGLMatrices.data(GL_MODELVIEW);
auto const lightcenter = modelview * interpolate(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f),
auto const lightcenter = modelview * glm::mix(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f),
static_cast<float>(TSubModel::fSquareDist / Submodel->fSquareMaxDist)); // pozycja punktu świecącego względem kamery
Submodel->fCosViewAngle = glm::dot(glm::normalize(modelview * glm::vec4(0.f, 0.f, -1.f, 1.f) - lightcenter), glm::normalize(-lightcenter));
@@ -4236,7 +4236,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
// additionally reduce light strength for farther sources in rain or snow
if (Global.Overcast > 0.75f)
{
float const precipitationfactor{interpolate(interpolate(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)};
float const precipitationfactor{std::lerp(std::lerp(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)};
lightlevel *= precipitationfactor;
}
@@ -4263,7 +4263,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
if (Global.Overcast > 1.0f)
{
// fake fog halo
float const fogfactor{interpolate(1.5f, 1.f, std::clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)};
float const fogfactor{std::lerp(1.5f, 1.f, std::clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)};
model_ubs.param[1].x = pointsize * fogfactor * 4.0f;
model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * std::min(1.f, lightlevel) * 0.5f);

View File

@@ -1507,7 +1507,7 @@ bool
opengl_renderer::Render( world_environment *Environment ) {
// calculate shadow tone, based on positions of celestial bodies
m_shadowcolor = interpolate(
m_shadowcolor = glm::mix(
glm::vec4{ colors::shadow },
glm::vec4{ colors::white },
std::clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f );
@@ -1570,7 +1570,7 @@ opengl_renderer::Render( world_environment *Environment ) {
auto const fogfactor { std::clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies
float const duskfactor = 1.0f - std::clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f;
glm::vec3 suncolor = interpolate(
glm::vec3 suncolor = glm::mix(
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 ),
duskfactor );
@@ -1586,7 +1586,7 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef( sunposition.x, sunposition.y, sunposition.z ); // początek układu zostaje bez zmian
float const size = interpolate( // TODO: expose distance/scale factor from the moon object
float const size = std::lerp( // TODO: expose distance/scale factor from the moon object
0.0325f,
0.0275f,
std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );
@@ -1619,7 +1619,7 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef( moonposition.x, moonposition.y, moonposition.z );
float const size = interpolate( // TODO: expose distance/scale factor from the moon object
float const size = std::lerp( // TODO: expose distance/scale factor from the moon object
0.0160f,
0.0135f,
std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );
@@ -1662,8 +1662,8 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLightModelfv(
GL_LIGHT_MODEL_AMBIENT,
glm::value_ptr(
interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
* interpolate( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds
glm::mix( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
* std::lerp( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds
* 0.5f // arbitrary adjustment factor
) );
// render
@@ -2911,7 +2911,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
auto const lightcenter =
modelview
* interpolate(
* glm::mix(
glm::vec4( 0.f, 0.f, -0.05f, 1.f ),
glm::vec4( 0.f, 0.f, -0.25f, 1.f ),
static_cast<float>( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery
@@ -2933,8 +2933,8 @@ opengl_renderer::Render( TSubModel *Submodel ) {
// additionally reduce light strength for farther sources in rain or snow
if( Global.Overcast > 0.75f ) {
float const precipitationfactor{
interpolate(
interpolate( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ),
std::lerp(
std::lerp( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ),
1.f,
distancefactor ) };
lightlevel *= precipitationfactor;
@@ -2968,7 +2968,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
if( Global.Overcast > 1.f ) {
// fake fog halo
float const fogfactor {
interpolate(
std::lerp(
2.f, 1.f,
std::clamp( Global.fFogEnd / 2000, 0.f, 1.f ) )
* std::max( 1.f, Global.Overcast ) };
@@ -3343,7 +3343,7 @@ opengl_renderer::Render_precipitation() {
// ::glColor4fv( glm::value_ptr( glm::vec4( glm::min( glm::vec3( Global.fLuminance ), glm::vec3( 1 ) ), 1 ) ) );
::glColor4fv(
glm::value_ptr(
interpolate(
glm::mix(
0.5f * ( Global.DayLight.diffuse + Global.DayLight.ambient ),
colors::white,
0.5f * std::clamp( (float)Global.fLuminance, 0.f, 1.f ) ) ) );
@@ -3935,7 +3935,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
auto const lightcenter =
modelview
* interpolate(
* glm::mix(
glm::vec4( 0.f, 0.f, -0.05f, 1.f ),
glm::vec4( 0.f, 0.f, -0.10f, 1.f ),
static_cast<float>( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery

View File

@@ -60,7 +60,7 @@ void opengl_skydome::update() {
auto &colors{ skydome.colors() };
/*
float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
auto gamma = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
auto gamma = std::lerp( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
for( auto & color : colors ) {
color = glm::pow( color, gamma );
}

View File

@@ -282,7 +282,7 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
}
// determine bounding area from calculated bounding box
if( false == m_particles.empty() ) {
m_area.center = interpolate( boundingbox[ value_limit::min ], boundingbox[ value_limit::max ], 0.5 );
m_area.center = glm::mix(boundingbox[value_limit::min], boundingbox[value_limit::max], 0.5);
m_area.radius = 0.5 * ( glm::length( boundingbox[ value_limit::max ] - boundingbox[ value_limit::min ] ) );
}
else {