Toast Engine
Loading...
Searching...
No Matches
voxel_debug.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include "vulkan_renderer.hpp"
9
10#include <array>
11#include <chrono>
12#include <cstdint>
13#include <deque>
14#include <optional>
15#include <string_view>
18
19namespace renderer::voxel_debug {
20
22enum class View : uint8_t {
23 steps = 20,
24 traversal = 21,
25 bricks = 22,
26 volumes = 23,
27 materials = 24,
28 palette_id = 25,
29};
30
31[[nodiscard]]
32constexpr auto isView(uint32_t render_mode) noexcept -> bool {
33 return render_mode >= static_cast<uint32_t>(View::steps) && render_mode <= static_cast<uint32_t>(View::palette_id);
34}
35
36struct Rgb {
37 float r = 0.0f;
38 float g = 0.0f;
39 float b = 0.0f;
40};
41
43inline constexpr std::array<Rgb, 8> k_step_band_colors {
44 Rgb {0.10f, 0.15f, 0.55f},
45 Rgb {0.10f, 0.45f, 0.90f},
46 Rgb {0.10f, 0.75f, 0.75f},
47 Rgb {0.25f, 0.80f, 0.25f},
48 Rgb {0.90f, 0.85f, 0.15f},
49 Rgb {0.95f, 0.50f, 0.10f},
50 Rgb {0.90f, 0.15f, 0.10f},
51 Rgb {0.85f, 0.20f, 0.85f},
52};
53inline constexpr std::array<uint32_t, 8> k_step_band_starts {1, 4, 8, 16, 32, 64, 128, 256};
54inline constexpr Rgb k_exhausted_color {1.0f, 1.0f, 1.0f};
55inline constexpr Rgb k_uniform_brick_color {0.20f, 0.40f, 0.95f};
56inline constexpr Rgb k_shared_brick_color {0.25f, 0.75f, 0.30f};
57inline constexpr Rgb k_owned_brick_color {0.95f, 0.55f, 0.12f};
58inline constexpr Rgb k_default_material_color {0.90f, 0.10f, 0.90f};
59
61struct Probe {
63 voxel::RayHit hit;
64
65 glm::vec3 world_position {0.0f};
66 float distance = 0.0f;
67
69 glm::ivec3 face {0};
70
71 uint32_t brick_entry = 0;
72 voxel::PaletteEntry palette_entry {};
73 float max_emissive = 1.0f;
74};
75
81
83 std::optional<Probe> hit;
84 std::optional<MissProbe> miss;
85};
86
89[[nodiscard]]
90auto probe(const VulkanRenderer::RenderFrame& frame, glm::vec2 cursor) -> std::optional<ProbeResult>;
91
93class Monitor {
94public:
95 void update(const VulkanRenderer::RenderFrame& frame);
96
98 void drawOverlay(const VulkanRenderer::RenderFrame& frame) const;
99
101 void drawPanel(const VulkanRenderer::RenderFrame& frame) const;
102
103private:
104 uint64_t m_sequence = 0;
105 uint32_t m_frames_since_upload = 0;
106 std::deque<std::chrono::steady_clock::time_point> m_uploads;
107
108 std::optional<ProbeResult> m_probe;
109};
110
111}
Render thread only.
Definition voxel_debug.hpp:93
void drawPanel(const VulkanRenderer::RenderFrame &frame) const
Call inside the Toast Debug window.
Definition voxel_debug.cpp:512
void drawOverlay(const VulkanRenderer::RenderFrame &frame) const
Draws nothing outside a voxel view.
Definition voxel_debug.cpp:446
Definition vulkan_renderer.hpp:377
Definition vulkan_renderer.hpp:286
The costliest box the cursor ray entered without hitting anything.
Definition voxel_debug.hpp:77
Definition voxel_debug.hpp:82
From voxel::marchRay over the uploaded data.
Definition voxel_debug.hpp:61
glm::ivec3 face
Volume space and zero when the ray started inside a solid voxel.
Definition voxel_debug.hpp:69
Definition voxel_debug.hpp:36
16 bytes and the offsets are a shader contract
Definition palette.hpp:26
Definition ray_march.hpp:21
View
Mirrors lighting.slang kRenderModeVoxel and the editor RenderMode enum.
Definition voxel_debug.hpp:22
constexpr std::array< Rgb, 8 > k_step_band_colors
Mirrors voxel.slang kStepBandColors.
Definition voxel_debug.hpp:43