18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 06:12:41 +01:00

Glare of light points: the glare in a function of its own, the define of its buffer with std::format

Render_Glare draws the glare around a light point, so Render_Alpha keeps its nesting. The define of GLARE_SSBO_BINDING is
appended with std::format after the chain of the common defines, the luminance is cast to float explicitly (the same value) and
the empty default of walk_light_reference says why it's empty.
This commit is contained in:
pwarszawski
2026-11-15 17:05:11 +01:00
parent 2dd53bc97b
commit e3584e706b
3 changed files with 49 additions and 36 deletions
+4 -1
View File
@@ -2,6 +2,8 @@
#include "glsl_common.h"
#include "rendering/common/shadersource.h"
#include <format>
std::string gl::glsl_common;
void gl::glsl_common_setup()
@@ -110,7 +112,6 @@ void gl::glsl_common_setup()
"#define SKY_OCCLUSION_HEIGHT_TEX " + std::to_string(SKY_OCCLUSION_HEIGHT_TEX) + "\n" +
"#define SKY_OCCLUSION_TEX " + std::to_string(SKY_OCCLUSION_TEX) + "\n" +
"#define CAB_PROBE_SSBO_BINDING " + std::to_string(CAB_PROBE_SSBO_BINDING) + "\n" +
"#define GLARE_SSBO_BINDING " + std::to_string(GLARE_SSBO_BINDING) + "\n" +
"#define CAB_PROBE_SH_SIZE " + std::to_string(CAB_PROBE_SH_SIZE) + "\n" +
"#define CAB_PROBE_SH_GROUP_SIZE " + std::to_string(CAB_PROBE_SH_GROUP_SIZE) + "\n" +
"#define WEATHER_UBO_BINDING " + std::to_string(WEATHER_UBO_BINDING) + "\n" +
@@ -119,6 +120,8 @@ void gl::glsl_common_setup()
"#define FOG_HORIZON_SAMPLES " + std::to_string(FOG_HORIZON_SAMPLES) + "\n" +
"#define WEATHER_GROUP_SIZE " + std::to_string(WEATHER_GROUP_SIZE) + "\n" +
"#define FOG_VOLUME_BIAS " + std::to_string(FOG_VOLUME_BIAS) + "\n";
// the counts of the samples of the light points seen, which their glares are made as bright as
glsl_common += std::format("#define GLARE_SSBO_BINDING {}\n", GLARE_SSBO_BINDING);
}
std::string gl::glsl_settings_defines()
+39 -34
View File
@@ -3110,6 +3110,44 @@ void scene_walk::Render_Alpha_text(TSubModel *Submodel)
}
}
void scene_walk::Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool const Pointlight)
{
// luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
auto glarelevel{std::clamp(std::max<float>(static_cast<float>(0.6f - Global.fLuminance), // reduce the glare in bright daylight
Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
0.f, 1.f)};
// view angle attenuation
float const anglefactor{Pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
glarelevel *= anglefactor;
if (glarelevel > 0.0f)
{
walk_glare(true);
::glPushMatrix();
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef(Lightcenter.x, Lightcenter.y, Lightcenter.z); // początek układu zostaje bez zmian
::glRotated(std::atan2(Lightcenter.x, Lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
Submodel->f4Diffuse :
Submodel->DiffuseOverride);
walk_program( walk_shader::billboard );
walk_texture(0, m_glaretexture);
model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
// main draw call
// drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
walk_glare_draw(Submodel, m_billboardgeometry);
walk_glare(false);
::glPopMatrix();
}
}
void scene_walk::Render_Alpha(TSubModel *Submodel)
{
// renderowanie przezroczystych przez DL
@@ -3289,40 +3327,7 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
// the point is drawn only inside its visibility cone, so the glare is too
if (pointdrawn && (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f))
{
// luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
auto glarelevel{std::clamp(std::max<float>(0.6f - Global.fLuminance, // reduce the glare in bright daylight
Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
0.f, 1.f)};
// view angle attenuation
float const anglefactor{pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
glarelevel *= anglefactor;
if (glarelevel > 0.0f)
{
walk_glare(true);
::glPushMatrix();
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef(lightcenter.x, lightcenter.y, lightcenter.z); // początek układu zostaje bez zmian
::glRotated(std::atan2(lightcenter.x, lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
Submodel->f4Diffuse :
Submodel->DiffuseOverride);
walk_program( walk_shader::billboard );
walk_texture(0, m_glaretexture);
model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
// main draw call
// drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
walk_glare_draw(Submodel, m_billboardgeometry);
walk_glare(false);
::glPopMatrix();
}
Render_Glare(Submodel, lightcenter, pointlight);
}
}
+6 -1
View File
@@ -274,7 +274,10 @@ class scene_walk
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;
// the point of the light drawn once more right after walk_light_query(), unseen and whole, for the backend which makes the
// glare as bright as the part of the point seen (the opengl renderer); by default nothing
virtual void walk_light_reference(gfx::geometry_handle const &Geometry) {}
virtual void walk_light_reference(gfx::geometry_handle const &Geometry)
{
// a backend which doesn't scale the glare by the part of the point seen has nothing to draw here
}
// what the backend may draw itself (the gpu culling of the opengl renderer); by default the walk draws everything
// the start of the walk of a region
virtual void walk_region_begin() {}
@@ -637,6 +640,8 @@ class scene_walk
private:
static float editor_ortho_reach();
// the glare around a light point drawn just before, Lightcenter in view space
void Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool Pointlight);
};
} // namespace gfx