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

Vulkan ray tracing: trace only visible reflections, sun shadow from the shadow map, foliage switch and timings

This commit is contained in:
2026-10-25 16:09:19 +01:00
parent 08f4f6ed60
commit e201c83825
6 changed files with 87 additions and 17 deletions

View File

@@ -23,6 +23,8 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/utilities.h"
#include "imgui/imgui.h"
#include <cstdio>
namespace
{
@@ -323,7 +325,14 @@ void vulkan14_renderer::draw_debug_ui()
{
ImGui::Checkbox("ray traced reflections where the screen has none (gfx.raytracing)", &m_raytracingon);
ImGui::SliderFloat("range of their rays and of the scenery, m (gfx.raytracing.range)", &Global.gfx_raytracing_range, 10.f, 5000.f, "%.0f", ImGuiSliderFlags_Logarithmic);
ImGui::Checkbox("alpha tested geometry (foliage) in the traced reflections", &m_rtfoliage);
raytracing = m_context->scene.raytracing->info();
if (m_raytracingon)
{
char cpu[96];
std::snprintf(cpu, sizeof(cpu), "\nprocessor: walk %.2f ms, build %.2f ms, %zu draws", m_rtwalkms, m_rtbuildms, m_rtdraws.size());
raytracing += cpu;
}
}
else
{

View File

@@ -33,6 +33,8 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/utilities.h"
#include "utilities/color.h"
#include <chrono>
namespace
{
@@ -1351,7 +1353,7 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
scene_ubs.shadow_fit = glm::vec4{0.f};
// the reflections: the ground below the horizon of the environment map, and the screen space ones set up for the colour pass of
// the main view only
scene_ubs.env_params = glm::vec4{Global.gfx_ambient_groundalbedo, 0.f, 0.f, 0.f};
scene_ubs.env_params = glm::vec4{Global.gfx_ambient_groundalbedo, (m_rtfoliage ? 0.f : 1.f), 0.f, 0.f};
gfx::screen_reflections::clear(scene_ubs);
if (vp.main)
@@ -1774,6 +1776,7 @@ void vulkan14_renderer::render_ray_scene(viewport_config &Viewport)
{
auto &ctx{*m_context};
auto &scene{ctx.scene};
auto const walkstart{std::chrono::steady_clock::now()};
m_rtdraws.clear();
m_rtinstances.clear();
auto const skipvehicle{m_shadowskipvehicle};
@@ -1797,9 +1800,13 @@ void vulkan14_renderer::render_ray_scene(viewport_config &Viewport)
m_renderpass = colourpass;
setup_matrices();
auto const buildstart{std::chrono::steady_clock::now()};
ctx.passes.begin_pass("ray tracing scene");
scene.raytracing->build(ctx.commands, ctx.slot, ctx.uploads.current_value(), m_framestamp, m_rtdraws, ctx.images);
ctx.passes.end_pass();
auto const buildend{std::chrono::steady_clock::now()};
m_rtwalkms += (std::chrono::duration<double, std::milli>(buildstart - walkstart).count() - m_rtwalkms) * 0.05;
m_rtbuildms += (std::chrono::duration<double, std::milli>(buildend - buildstart).count() - m_rtbuildms) * 0.05;
}
// a draw of the walk noted for the ray tracing: the chunk with its data on the gpu, the transform, the texture and the colour of the

View File

@@ -634,7 +634,8 @@ void ray_tracing::build(command_stream *Commands, std::uint32_t const Slot, std:
}
}
instance.instanceCustomIndex = written;
instance.mask = 0xFF;
// the shaders tell the alpha tested ones by the mask (shaders/vk14/rt_reflections.glsl, RT_MASK_*)
instance.mask = (alpha ? 0x02 : 0x01);
instance.instanceShaderBindingTableRecordOffset = 0;
// the models have faces of one side, seen from both in the reflections; an alpha tested texture leaves holes in its faces
instance.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR | (alpha ? VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR : VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR);

View File

@@ -281,6 +281,9 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk
void gather_ray_draw(gfx::geometry_handle const &Geometry);
bool m_rtgather{false};
bool m_raytracingon{true}; // switched off in the debug window
bool m_rtfoliage{true}; // the alpha tested geometry in the traced reflections, switched off in the debug window
double m_rtwalkms{0.0}; // the processor time of the walk and of the build of the ray tracing, averaged
double m_rtbuildms{0.0};
std::vector<vk14::ray_draw> m_rtdraws;
std::vector<glm::mat4> m_rtinstances; // the modelviews of the instanced draws noted (walk_instances())
void render_picking(rendermode const Mode);