[PR #3650] [MERGED] Draw lightning bolts: sample inside the white sprite #5124

Closed
opened 2026-11-03 05:10:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3650
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3171


📝 Commits (1)

  • 2f3f8d7 Draw lightning bolts: sample inside the white sprite

📊 Changes

3 files changed (+261 additions, -5 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx/lightning.rs (+10 -1)
📝 crates/horizon-client-render/src/gfx/lightning/tests/mod.rs (+250 -0)
📝 crates/horizon-client/src/game.rs (+1 -4)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Fixes #3171

Lightning bolts weren't drawn. The bolt entity arrived, flashed and was counted (status.lightning showed bolts: 3), but nothing showed on screen. I first saw this on a vanilla server, but singleplayer draws bolts through the same path and had the same problem.

Root cause: the bolt's quads are untextured in vanilla (RenderTypes.lightning is position plus colour). Horizon draws them through the entity atlas with one UV for every vertex, the "white texel". That UV was the white sprite's corner, [white.u0, white.v0]. A sprite's corner sits on its border with the next atlas texels. The atlas sampler is wgpu's default (nearest), so for most fragments it picked those transparent neighbours. The bolt came out as a few scattered pink-white pixels. Its geometry and placement were right: with the vertex colour forced to opaque magenta, only a dotted 1-pixel trace showed.

The fix samples the middle of the white sprite, as the clouds already do. A new gfx::lightning::white_uv(&Rect) does that, and the game's frame now uses it for lightning::Input.uv.

Not in this PR: dragon.rs dragon_rays (the dragon's death beams) also samples [white.u0, white.v0], so it is probably hit by the same problem. I couldn't get a dragon death on screen to check, so I left it alone. Once it's checked, it can switch to white_uv the same way.

Vanilla reference

  • LightningBoltRenderer.submit / lambda$submit$0 and quad: vertex positions and colour (0.45, 0.45, 0.5, alpha 0.3). The geometry is unchanged here (geometry_matches_pinned_vanilla_vertex_digest still passes).
  • RenderTypes.lightning: no texture, so the colour must reach the frame as it is. With the white texel actually sampled, it now does.

Tests

In crates/horizon-client-render/src/gfx/lightning/tests/mod.rs:

  • white_uv_is_inside_the_white_sprite (runs by default): for a 4x4 horizon/white sprite in an atlas, the sampled point is at least a texel inside the sprite.
  • bolt_through_the_atlas_white_sprite_is_fully_drawn (GPU, #[ignore] like the existing GPU test there). It draws a bolt 14 blocks in front of a 70° camera through the retained lightning renderer twice. One draw goes through an atlas that is transparent except for the white sprite, sampled with the default (nearest) sampler, as in the game. The other goes through an all-white texture. Both must produce the same pixels.

Before (only white_uv put back to the corner [white.u0, white.v0]):

cargo test -p horizon-client-render --lib gfx::lightning -- --include-ignored --test-threads 1
test gfx::lightning::tests::bolt_through_the_atlas_white_sprite_is_fully_drawn ... FAILED
test gfx::lightning::tests::white_uv_is_inside_the_white_sprite ... FAILED
assertion `left == right` failed: pixels drawn through the atlas
  left: 2329
 right: 2912
u at texel 40
test result: FAILED. 5 passed; 2 failed

After:

test gfx::lightning::tests::bolt_through_the_atlas_white_sprite_is_fully_drawn ... ok
test gfx::lightning::tests::cache_tracks_seed_lifecycle_movement_and_atlas_reload ... ok
test gfx::lightning::tests::geometry_matches_pinned_vanilla_vertex_digest ... ok
test gfx::lightning::tests::long_flash_sequence_keeps_only_active_seeds ... ok
test gfx::lightning::tests::retained_geometry_matches_original_generator ... ok
test gfx::lightning::tests::retained_gpu_draw_matches_transient_additive_draw ... ok
test gfx::lightning::tests::white_uv_is_inside_the_white_sprite ... ok
test result: ok. 7 passed; 0 failed

In game

Setup: a local vanilla 26.3 dedicated server (offline mode, flat world). A datapack function runs summon lightning_bolt 0 -60 14 and reschedules itself every 4 ticks, which keeps a bolt alive long enough for a screenshot. Horizon is joined with horizon-ctl connect, standing at 0 -60 0 and facing the strike point (RTX 5080, Vulkan).

  • Before (origin/main): status.lightning reports {"bolts": 3, "flash": 2, ...}, but the screenshot shows only the fire at the strike point and no bolt.
  • After: the bolt is drawn as a bright, wide, jagged column from the strike point up into the sky. The same happens in singleplayer with /summon lightning_bolt.

Self-check

tools/pr_ready.py wasn't run on this Windows machine. I ran these instead, with CARGO_TARGET_DIR set:

  • cargo fmt --all -- --check: clean
  • cargo clippy --profile fast -p horizon-client-render --all-targets -- -D warnings: clean
  • cargo clippy --profile fast -p horizon-client --features mods --all-targets -- -D warnings: clean
  • cargo test --profile fast -p horizon-client-render --lib gfx::lightning -- --include-ignored --test-threads 1: 7 passed
  • cargo build --profile fast -p horizon-client --features mods --bins, then the server and singleplayer checks above

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3650 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3171` --- ### 📝 Commits (1) - [`2f3f8d7`](https://github.com/horizon-rust/horizon/commit/2f3f8d7a7fc8bec8a758ce16245ceec7f1017109) Draw lightning bolts: sample inside the white sprite ### 📊 Changes **3 files changed** (+261 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx/lightning.rs` (+10 -1) 📝 `crates/horizon-client-render/src/gfx/lightning/tests/mod.rs` (+250 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -4) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3171 Lightning bolts weren't drawn. The bolt entity arrived, flashed and was counted (`status.lightning` showed `bolts: 3`), but nothing showed on screen. I first saw this on a vanilla server, but singleplayer draws bolts through the same path and had the same problem. Root cause: the bolt's quads are untextured in vanilla (`RenderTypes.lightning` is position plus colour). Horizon draws them through the entity atlas with one UV for every vertex, the "white texel". That UV was the white sprite's corner, `[white.u0, white.v0]`. A sprite's corner sits on its border with the next atlas texels. The atlas sampler is wgpu's default (nearest), so for most fragments it picked those transparent neighbours. The bolt came out as a few scattered pink-white pixels. Its geometry and placement were right: with the vertex colour forced to opaque magenta, only a dotted 1-pixel trace showed. The fix samples the middle of the white sprite, as the clouds already do. A new `gfx::lightning::white_uv(&Rect)` does that, and the game's frame now uses it for `lightning::Input.uv`. Not in this PR: `dragon.rs` `dragon_rays` (the dragon's death beams) also samples `[white.u0, white.v0]`, so it is probably hit by the same problem. I couldn't get a dragon death on screen to check, so I left it alone. Once it's checked, it can switch to `white_uv` the same way. ## Vanilla reference - `LightningBoltRenderer.submit` / `lambda$submit$0` and `quad`: vertex positions and colour (0.45, 0.45, 0.5, alpha 0.3). The geometry is unchanged here (`geometry_matches_pinned_vanilla_vertex_digest` still passes). - `RenderTypes.lightning`: no texture, so the colour must reach the frame as it is. With the white texel actually sampled, it now does. ## Tests In `crates/horizon-client-render/src/gfx/lightning/tests/mod.rs`: - `white_uv_is_inside_the_white_sprite` (runs by default): for a 4x4 `horizon/white` sprite in an atlas, the sampled point is at least a texel inside the sprite. - `bolt_through_the_atlas_white_sprite_is_fully_drawn` (GPU, `#[ignore]` like the existing GPU test there). It draws a bolt 14 blocks in front of a 70° camera through the retained lightning renderer twice. One draw goes through an atlas that is transparent except for the white sprite, sampled with the default (nearest) sampler, as in the game. The other goes through an all-white texture. Both must produce the same pixels. Before (only `white_uv` put back to the corner `[white.u0, white.v0]`): ``` cargo test -p horizon-client-render --lib gfx::lightning -- --include-ignored --test-threads 1 test gfx::lightning::tests::bolt_through_the_atlas_white_sprite_is_fully_drawn ... FAILED test gfx::lightning::tests::white_uv_is_inside_the_white_sprite ... FAILED assertion `left == right` failed: pixels drawn through the atlas left: 2329 right: 2912 u at texel 40 test result: FAILED. 5 passed; 2 failed ``` After: ``` test gfx::lightning::tests::bolt_through_the_atlas_white_sprite_is_fully_drawn ... ok test gfx::lightning::tests::cache_tracks_seed_lifecycle_movement_and_atlas_reload ... ok test gfx::lightning::tests::geometry_matches_pinned_vanilla_vertex_digest ... ok test gfx::lightning::tests::long_flash_sequence_keeps_only_active_seeds ... ok test gfx::lightning::tests::retained_geometry_matches_original_generator ... ok test gfx::lightning::tests::retained_gpu_draw_matches_transient_additive_draw ... ok test gfx::lightning::tests::white_uv_is_inside_the_white_sprite ... ok test result: ok. 7 passed; 0 failed ``` ## In game Setup: a local vanilla 26.3 dedicated server (offline mode, flat world). A datapack function runs `summon lightning_bolt 0 -60 14` and reschedules itself every 4 ticks, which keeps a bolt alive long enough for a screenshot. Horizon is joined with `horizon-ctl connect`, standing at 0 -60 0 and facing the strike point (RTX 5080, Vulkan). - Before (`origin/main`): `status.lightning` reports `{"bolts": 3, "flash": 2, ...}`, but the screenshot shows only the fire at the strike point and no bolt. - After: the bolt is drawn as a bright, wide, jagged column from the strike point up into the sky. The same happens in singleplayer with `/summon lightning_bolt`. ## Self-check `tools/pr_ready.py` wasn't run on this Windows machine. I ran these instead, with `CARGO_TARGET_DIR` set: - `cargo fmt --all -- --check`: clean - `cargo clippy --profile fast -p horizon-client-render --all-targets -- -D warnings`: clean - `cargo clippy --profile fast -p horizon-client --features mods --all-targets -- -D warnings`: clean - `cargo test --profile fast -p horizon-client-render --lib gfx::lightning -- --include-ignored --test-threads 1`: 7 passed - `cargo build --profile fast -p horizon-client --features mods --bins`, then the server and singleplayer checks above 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:23 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5124
No description provided.