F3+4 shows the lightmap texture in the bottom right corner

DebugScreenOverlay.toggleLightmapTexture and showLightmapTexture: the 16x16
lightmap at 64x64 on a black border, 2 pixels from the corner, sky light up
and block light right, as vanilla's flipped blit. It shares the bottom of the
screen with the F3+2 and F3+3 charts, so each switch turns the others off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 10:31:14 +02:00
parent 6ae018055d
commit 1f4154c0df
4 changed files with 64 additions and 6 deletions
+43
View File
@@ -62,6 +62,8 @@ pub struct DebugCharts {
pub fps: bool,
/// `renderNetworkCharts` (F3+3).
pub network: bool,
/// `renderLightmapTexture` (F3+4).
pub lightmap: bool,
/// `frameTimeLogger`: nanoseconds between frames.
pub frame_times: SampleLogger,
/// `tickTimeLogger`: the integrated server's ticks.
@@ -80,6 +82,7 @@ impl DebugCharts {
if self.fps {
*overlay = true;
self.network = false;
self.lightmap = false;
}
}
/// `toggleNetworkCharts`.
@@ -88,6 +91,16 @@ impl DebugCharts {
if self.network {
*overlay = true;
self.fps = false;
self.lightmap = false;
}
}
/// `toggleLightmapTexture`.
pub fn toggle_lightmap(&mut self, overlay: &mut bool) {
self.lightmap = !*overlay || !self.lightmap;
if self.lightmap {
*overlay = true;
self.fps = false;
self.network = false;
}
}
/// `reset`: leaving a world.
@@ -165,6 +178,22 @@ impl DebugCharts {
}
}
/// The lightmap view (`showLightmapTexture`): the 16 by 16 texture at 64
/// by 64 in the bottom right corner on a black border, sky light up and
/// block light right (the blit flips the texture's rows). `pixels` are RGBA
/// rows of sky level by block level.
pub fn lightmap(pixels: &[u8; 16 * 16 * 4], width: i32, height: i32) -> Vec<GuiDraw> {
let (x, y) = (width - 64 - 2, height - 64 - 2);
let mut out = vec![fill(x - 1, y - 1, x + 64 + 1, y + 64 + 1, 0xFF00_0000)];
for (i, p) in pixels.as_chunks::<4>().0.iter().enumerate() {
let (sky, block) = ((i / 16) as i32, (i % 16) as i32);
let color = argb(255, u32::from(p[0]), u32::from(p[1]), u32::from(p[2]));
let (cx, cy) = (x + block * 4, y + (15 - sky) * 4);
out.push(fill(cx, cy, cx + 4, cy + 4, color));
}
out
}
/// The four charts and what each needs to scale its bars.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Chart {
@@ -470,6 +499,9 @@ mod tests {
assert!(c.network && !c.fps);
c.toggle_network(&mut overlay);
assert!(!c.network && overlay);
c.toggle_lightmap(&mut overlay);
c.toggle_fps(&mut overlay);
assert!(c.fps && !c.lightmap);
// With the overlay hidden, the key shows it again with the chart on.
c.toggle_fps(&mut overlay);
overlay = false;
@@ -477,6 +509,17 @@ mod tests {
assert!(overlay && c.fps);
}
#[test]
fn the_lightmap_puts_full_sky_light_at_the_top_left() {
let mut pixels = [0u8; 16 * 16 * 4];
// Sky 15, block 0: the last row's first texel.
pixels[15 * 64..15 * 64 + 4].copy_from_slice(&[10, 20, 30, 255]);
let draws = lightmap(&pixels, 427, 240);
assert_eq!(draws[0], fill(360, 173, 426, 239, 0xFF00_0000));
assert_eq!(draws.len(), 257);
assert!(draws.contains(&fill(361, 174, 365, 178, 0xFF0A_141E)));
}
#[test]
fn ticks_and_bandwidth_log_their_differences() {
let mut c = DebugCharts::default();
+7
View File
@@ -3725,6 +3725,13 @@ impl Game<'_> {
self.remote.is_some(),
);
hud_layout::paint(&mut batch, atlas, &charts);
if self.debug_charts.lightmap
&& let Some(r) = &self.renderer
{
let view =
horizon_client::debug_chart::lightmap(&r.lightmap_pixels, w as i32, h as i32);
hud_layout::paint(&mut batch, atlas, &view);
}
}
if !self.ui.hide_gui
&& let Some((text, at)) = &self.message
+8 -5
View File
@@ -248,7 +248,7 @@ impl Game<'_> {
if remote { "Bandwidth + Ping" } else { "Ping" },
c.network
),
chart("key.debug.lightmapTexture", "Lightmap", false),
chart("key.debug.lightmapTexture", "Lightmap", c.lightmap),
),
format!("To edit: press {}", key("key.debug.debugOptions")),
]
@@ -420,14 +420,17 @@ impl Game<'_> {
self.debug_charts.toggle_network(&mut self.debug);
true
}
DebugAction::LightmapTexture => {
self.debug_charts.toggle_lightmap(&mut self.debug);
true
}
// Screens and overlays Horizon does not draw yet (the debug
// options screen, the profiler and its chart, the lightmap, the
// texture dump): the keys are used up as in vanilla.
// options screen, the profiler and its chart, the texture dump):
// the keys are used up as in vanilla.
DebugAction::DebugOptions
| DebugAction::DumpDynamicTextures
| DebugAction::Profiling
| DebugAction::ProfilingChart
| DebugAction::LightmapTexture => true,
| DebugAction::ProfilingChart => true,
DebugAction::ShowHitboxes
| DebugAction::ShowChunkBorders
| DebugAction::SwitchGameMode
+6 -1
View File
@@ -197,6 +197,9 @@ pub struct Renderer {
gpu_timer: Option<timing::GpuTimer>,
/// GPU frame times (ms) read back since the caller last drained them.
pub gpu_times: Vec<f32>,
/// The last lightmap written, RGBA rows of sky level by block level
/// (F3+4 shows it).
pub lightmap_pixels: [u8; 16 * 16 * 4],
/// Time the last `render` spent blocked on the GPU or the display
/// (acquiring, presenting, offscreen pacing), excluded from CPU time.
pub last_wait: std::time::Duration,
@@ -1363,6 +1366,7 @@ impl Renderer {
in_flight: std::collections::VecDeque::new(),
gpu_timer,
gpu_times: Vec::new(),
lightmap_pixels: [0; 16 * 16 * 4],
last_wait: std::time::Duration::ZERO,
last_encode: std::time::Duration::ZERO,
window,
@@ -1728,7 +1732,7 @@ impl Renderer {
world_projection(fov_degrees, aspect, far) * bob * crate::camera::view_matrix(yaw, pitch)
}
fn update_lightmap(
&self,
&mut self,
sky: &Sky,
darkness: f32,
gamma: f32,
@@ -1784,6 +1788,7 @@ impl Renderer {
depth_or_array_layers: 1,
},
);
self.lightmap_pixels = pixels;
}
fn animate(&mut self, tick: u64) {
animate_sprites(