17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-29 11:37:29 +01:00

Steady the volumetric fog and add a switch for the old headlight beams

This commit is contained in:
2026-10-16 23:23:51 +02:00
parent 8b929fc1da
commit 6ee628aaa5
9 changed files with 114 additions and 32 deletions

View File

@@ -823,6 +823,7 @@ void opengl46_renderer::draw_debug_ui()
{
ImGui::Checkbox("clustered lights (off: the first dynamiclights headlights)", &Global.gfx_lights_clustered);
ImGui::Checkbox("heatmap", &Global.gfx_lights_clusterheatmap);
ImGui::Checkbox("beams of vehicle headlights (gfx.lights.headlights)", &Global.gfx_lights_headlights);
if (auto const &clusters{m_viewports.front()->clusters})
{
auto const &params{clusters->params()};
@@ -6405,8 +6406,8 @@ void opengl46_renderer::Update_Lights(light_array &Lights, bool const Headlights
for (auto const &scenelight : Lights.data)
{
if (!Headlights || scenelight.intensity == 0.f) {
// all lights past this one are bound to be off
if (!Headlights || !Global.gfx_lights_headlights || scenelight.intensity == 0.f) {
// all lights past this one are bound to be off (or the beams of the headlights are turned off altogether)
break;
}
auto const lightoffset = glm::vec3{scenelight.position - camera};
@@ -6734,7 +6735,7 @@ void opengl46_renderer::Render_headlight_shadows()
// the headlights which shine, the most important first (in the order of Update_Lights()), whose beam may be seen within the
// reach of the shadows
m_headlightshadowpicked.clear();
auto const count{(std::clamp(Global.gfx_lights_shadows, 0, 3) > 0) ? std::clamp(Global.gfx_lights_shadows_headlights, 0, static_cast<int>(gl::MAX_HEADLIGHT_SHADOWS)) : 0};
auto const count{(Global.gfx_lights_headlights && (std::clamp(Global.gfx_lights_shadows, 0, 3) > 0)) ? std::clamp(Global.gfx_lights_shadows_headlights, 0, static_cast<int>(gl::MAX_HEADLIGHT_SHADOWS)) : 0};
if (count > 0)
{
m_headlightshadowcandidates.clear();

View File

@@ -519,15 +519,21 @@ void opengl46_weather::render_view(glm::mat4 const &Projection, glm::mat4 const
{
m_fog_timer.begin();
auto const farthest{std::max(Global.gfx_fog_range, FOG_VOLUME_NEAR * 4.f)};
// the cells are sampled at another depth in every frame, in the Halton sequence of 2
auto const jitter{[](int Frame) {
float value{0.f}, fraction{0.5f};
for (Frame = (Frame % 64) + 1; Frame > 0; Frame /= 2, fraction *= 0.5f)
value += fraction * static_cast<float>(Frame % 2);
// the cells are sampled at another point in every frame: along the depth in the Halton sequence of 2, across the view in
// those of 3 and 5 (fog_inject.comp moves the point of every cell by a value of its own)
auto const halton = [](int Index, int const Base) {
float value{0.f}, fraction{1.f};
for (; Index > 0; Index /= Base)
{
fraction /= static_cast<float>(Base);
value += fraction * static_cast<float>(Index % Base);
}
return value;
}(m_frame)};
};
auto const temporal{Global.gfx_fog_temporal && continuity(m_previous_fog)};
glm::vec4 const slicing{FOG_VOLUME_NEAR, farthest, static_cast<float>(m_fog_grid.z) / std::log(farthest / FOG_VOLUME_NEAR), temporal ? jitter : 0.5f};
auto const sample{(m_frame % 64) + 1};
glm::vec3 const jitter{temporal ? glm::vec3{halton(sample, 3), halton(sample, 5), halton(sample, 2)} : glm::vec3{0.5f}};
glm::vec4 const slicing{FOG_VOLUME_NEAR, farthest, static_cast<float>(m_fog_grid.z) / std::log((farthest + gl::FOG_VOLUME_BIAS) / (FOG_VOLUME_NEAR + gl::FOG_VOLUME_BIAS)), jitter.z};
bind_noise();
auto const next{1 - m_fog_current};
glBindImageTexture(0, m_fog_scattering[next], 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_RGBA16F);
@@ -540,9 +546,11 @@ void opengl46_weather::render_view(glm::mat4 const &Projection, glm::mat4 const
auto const previous{glm::vec3{m_previous_fog.camera - Camera}};
glProgramUniform3f(*m_inject_program, 5, previous.x, previous.y, previous.z);
auto const sunshadows{Global.gfx_fog_shadows && Global.gfx_shadowmap_enabled};
glProgramUniform4f(*m_inject_program, 6, temporal ? 0.25f : 1.f, Global.gfx_fog_lights, sunshadows ? 1.f : 0.f, Global.gfx_fog_shadows ? 1.f : 0.f);
auto const share{temporal ? std::clamp(Global.gfx_fog_temporal_share, 0.02f, 1.f) : 1.f};
glProgramUniform4f(*m_inject_program, 6, share, Global.gfx_fog_lights, sunshadows ? 1.f : 0.f, Global.gfx_fog_shadows ? 1.f : 0.f);
glProgramUniform1i(*m_inject_program, 7, Cablamp);
glProgramUniform2f(*m_inject_program, 8, m_previous_fog.slicing.x, m_previous_fog.slicing.z);
glProgramUniform2f(*m_inject_program, 9, jitter.x, jitter.y);
m_inject_program->dispatch(groups(m_fog_grid.x), groups(m_fog_grid.y), static_cast<GLuint>(m_fog_grid.z));
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
@@ -674,6 +682,7 @@ void opengl46_weather::draw_debug_ui()
ImGui::SliderFloat("lamps in the fog (gfx.fog.lights)", &Global.gfx_fog_lights, 0.f, 4.f);
ImGui::Checkbox("shadows of the sun and headlights in the fog (gfx.fog.shadows)", &Global.gfx_fog_shadows);
ImGui::Checkbox("fog blended over frames (gfx.fog.temporal)", &Global.gfx_fog_temporal);
ImGui::SliderFloat("share of a new frame in the fog (gfx.fog.temporal.share)", &Global.gfx_fog_temporal_share, 0.02f, 1.f);
char const *cloudlevels[]{"none", "low", "medium", "high", "ultra"};
ImGui::Combo("clouds (gfx.clouds)", &Global.gfx_clouds, cloudlevels, IM_ARRAYSIZE(cloudlevels));
ImGui::SliderFloat("cloud distance, m (gfx.clouds.distance)", &Global.gfx_clouds_distance, 5000.f, 200000.f, "%.0f", ImGuiSliderFlags_Logarithmic);