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

Draw the glare of a FreeSpotLight after its point

The glare of a light point is drawn without the depth test, conditioned
on the occlusion query of the point. That query was issued only after
the glare and is kept on the TSubModel, which every instance of a model
shares, so the glare of one lamp used what the query saw for whichever
instance drew that submodel last (earlier in the frame or in the last
frame): glares showed through walls and blinked while the camera moved.

The point (with its query) is now drawn first and the glare after it,
so the conditional render of the opengl renderer uses the query of this
very point of this instance in this frame. The glare is drawn only when
the point was, which already held, as both need the viewer inside the
visibility cone. The vulkan renderer keeps using the results of the
last frame.
This commit is contained in:
pwarszawski
2026-11-14 14:30:51 +01:00
parent 19fba58976
commit ba44b0c0d5
2 changed files with 43 additions and 43 deletions
+41 -42
View File
@@ -3218,48 +3218,8 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
// a point light (FalloffAngle 360) is seen all around
auto const pointlight{Submodel->fCosFalloffAngle <= -1.f};
if (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f)
{
if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
{
// only bother if the viewer is inside the visibility cone
// 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 light itself was seen in the last frame (an occlusion query of the opengl renderer)
walk_glare_draw(Submodel, m_billboardgeometry);
walk_glare(false);
::glPopMatrix();
}
}
}
// the glare is drawn after the point, where the occlusion query of this very point (of this instance, in this frame) saw it
auto pointdrawn{false};
if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
{
// kąt większy niż maksymalny stożek swiatła
@@ -3316,11 +3276,50 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
walk_draw(Submodel->m_geometry.handle);
walk_light_query(Submodel, false);
pointdrawn = true;
// post-draw reset
model_ubs.emission = 0.0f;
model_ubs.fog_density = 1.0f / m_fogrange;
::glPopMatrix();
}
}
// 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();
}
}
+2 -1
View File
@@ -266,7 +266,8 @@ class scene_walk
virtual void walk_timbers_expand(std::vector<glm::mat4> const &Origins, std::vector<gl::timber_range> const &Ranges) {}
virtual void walk_cull_face(bool const Enabled) = 0;
// the glare of a lamp: drawn without the depth test, added to what is there; drawn only where the point of the light was
// seen (walk_light_query() of the last frame, when the backend has it)
// seen (walk_light_query() of this point drawn just before it, when the backend has it: the opengl renderer uses
// the query at once, the vulkan renderer the result of the last frame)
virtual void walk_glare(bool const Enabled) = 0;
virtual void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) = 0;
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;