[PR #1084] [MERGED] Weather: rain heights from a cached MOTION_BLOCKING heightmap #3033

Closed
opened 2026-11-02 16:00:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1084
Author: @ludovic111
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @ludovic111

Base: main ← Head: fix/weather-frame-cost


📝 Commits (1)

  • b591c9d Weather: rain heights from a cached MOTION_BLOCKING heightmap, no per-column allocations

📊 Changes

4 files changed (+119 additions, -46 deletions)

View changed files

📝 crates/horizon-client/src/chunk.rs (+68 -13)
📝 crates/horizon-client/src/game.rs (+10 -14)
📝 crates/horizon-client/src/weather.rs (+33 -19)
📝 crates/horizon-client/src/world.rs (+8 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #899. Reported by rdbtCVS: 930 → 610 FPS when it snowed and 1310 → 600 FPS in rain (R5 5600X, RTX 4060).

What

Every frame in rain or snow, weather_geometry asked for the rain height of each of the 21 × 21 columns around the player. rain_height walked down block by block from 10 blocks above the weather box. For every block it took the world lookup and the facts lookup, and it matched leaves by name with name.contains("leaves"). Then tile built a Vec for every column it cut into whole-block pieces. Over open ground that is a few thousand block lookups per frame, which cost about 1 ms of CPU on the ThinkPad.

Vanilla reads level.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z) (WeatherEffectRenderer.extractRenderState), which comes from a heightmap the chunk keeps. This PR does the same:

  • Chunk keeps a lazily built MOTION_BLOCKING map next to its surface map (motion_blocking, a OnceLock<Box<[i16; 256]>>). set invalidates it when the write is at or above a column's height, as it already did for the surface map. Building it skips sections that are a single state that doesn't count, as the surface map does for air.
  • What counts is HeightmapType::MotionBlocking.is_opaque, the server's own heightmap rule (minecraft:blocks_motion_in_heightmap, or a block with a fluid), through Properties::heightmap_state. Before, Horizon used its own approximation: full collision, a fluid, or a name containing "leaves".
  • World::motion_blocking(x, z, …) gives MIN_Y for unloaded chunks, as before.
  • tile cuts the column with an iterator instead of building a Vec.

Change players can see

The rain height is now vanilla's. Two things change:

  • Rain and snow stop on every block in blocks_motion_in_heightmap, as in vanilla. That includes slabs, stairs, fences, walls, glass panes, beds and other blocks that aren't a full cube. Before, rain fell through a slab roof.
  • Roofs higher than 20 blocks above the player also stop rain. Before, the downward walk started 10 blocks above the weather box, so a roof higher than that was not seen. The rain sound tick and the splash particles use the same height.

Numbers

Same scene for both builds: seed 1234, the village at (-960, 90, 150) for clear and rain, snowy plains at (-1216, 90, 438) for snow. Mobs off and killed, standing still, horizon-ctl bench 5 s, conditions alternated within one game, medians.

Mac mini (M4 Pro), macOS, Metal, offscreen 1280x720, 8 runs per row. Both builds include #1079 (stars), so they differ only by this PR's commit. They ran in the order before, after, after, before. CI runners were loading the machine (load 32–64; the last "before" game ran at 64), which is why clear weather wanders. The prepare phase is the figure to read:

before this PR
clear: CPU frame / FPS 1.065 ms / 874 1.063 ms / 856
rain: CPU frame / FPS 1.703 ms / 561 1.163 ms / 759
snow: CPU frame / FPS 1.440 ms / 663 0.917 ms / 981
prepare, rain 0.869 ms 0.383 ms
prepare, snow 0.786 ms 0.349 ms

ThinkPad, Intel HD 620, Linux, Mesa Vulkan, offscreen 1280x720, nice 19, 8 runs per row (clear is within run-to-run noise):

main CPU this PR CPU main FPS this PR FPS
clear 2.264 ms 2.452 ms 274 267
rain 4.771 ms 3.520 ms 128 127
snow 4.123 ms 3.136 ms 160 158
prepare phase, rain 1.922 ms 0.901 ms

The HD 620 is GPU-bound in rain, at 7.5 ms of GPU per frame against 3.3 ms in clear weather, so its FPS doesn't move. That GPU cost is the overdraw of the rain columns with vanilla's weather pipeline (depth write, blend, discard), and it is the same on both builds.

Desktop, RTX 4080, Linux, Vulkan, offscreen 1280x720 (round 1 of 2; round 2 overlapped my own test run):

main this PR
clear 2952 FPS 2939 FPS
rain 1182 FPS (0.847 ms) 2125 FPS (0.470 ms)
snow 1248 FPS 2105 FPS
prepare, rain 0.506 ms 0.207 ms

Screenshots

In rain, on the ThinkPad, with the same seed and the same commands for both builds. Two roofs are placed three blocks above the ground: oak slabs on the left and oak planks on the right.

Standing under the slabs and looking up. On main, rain falls through the slab roof. With this PR it stops on the slabs, as in vanilla:

main this PR
main, under slabs this PR, under slabs

The wider view looks the same on both:

main this PR
main, rain this PR, rain

Checks

  • cargo fmt --all --check: clean.
  • cargo clippy -p horizon-client --all-targets -- -D warnings with set -o pipefail: exit 0. This is scoped to the touched crate because workspace-wide clippy fails on that machine on hidapi/libudev, which this PR doesn't touch.
  • cargo test -p horizon-client: all pass (lib 942, plus the integration tests). New tests: motion_blocking_follows_writes and pieces_cut_at_whole_numbers.
  • tools/parity.py --changed origin/main lists every harness (none has a pass history yet), so I ran the ones this touches, weather_render, heightmap, biome_weather and environment_render, on the desktop. On main at bc890421 all 4 pass. On bc890421 with this PR and #1079 all 4 pass.

🤖 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/1084 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/weather-frame-cost` --- ### 📝 Commits (1) - [`b591c9d`](https://github.com/horizon-rust/horizon/commit/b591c9dc64b7f45c133862132b8d73173dcd8195) Weather: rain heights from a cached MOTION_BLOCKING heightmap, no per-column allocations ### 📊 Changes **4 files changed** (+119 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/chunk.rs` (+68 -13) 📝 `crates/horizon-client/src/game.rs` (+10 -14) 📝 `crates/horizon-client/src/weather.rs` (+33 -19) 📝 `crates/horizon-client/src/world.rs` (+8 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #899. Reported by **rdbtCVS**: 930 → 610 FPS when it snowed and 1310 → 600 FPS in rain (R5 5600X, RTX 4060). ## What Every frame in rain or snow, `weather_geometry` asked for the rain height of each of the 21 × 21 columns around the player. `rain_height` walked down block by block from 10 blocks above the weather box. For every block it took the world lookup and the facts lookup, and it matched leaves by name with `name.contains("leaves")`. Then `tile` built a `Vec` for every column it cut into whole-block pieces. Over open ground that is a few thousand block lookups per frame, which cost about 1 ms of CPU on the ThinkPad. Vanilla reads `level.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z)` (`WeatherEffectRenderer.extractRenderState`), which comes from a heightmap the chunk keeps. This PR does the same: - `Chunk` keeps a lazily built MOTION_BLOCKING map next to its surface map (`motion_blocking`, a `OnceLock<Box<[i16; 256]>>`). `set` invalidates it when the write is at or above a column's height, as it already did for the surface map. Building it skips sections that are a single state that doesn't count, as the surface map does for air. - What counts is `HeightmapType::MotionBlocking.is_opaque`, the server's own heightmap rule (`minecraft:blocks_motion_in_heightmap`, or a block with a fluid), through `Properties::heightmap_state`. Before, Horizon used its own approximation: full collision, a fluid, or a name containing "leaves". - `World::motion_blocking(x, z, …)` gives `MIN_Y` for unloaded chunks, as before. - `tile` cuts the column with an iterator instead of building a `Vec`. ### Change players can see The rain height is now vanilla's. Two things change: - Rain and snow stop on every block in `blocks_motion_in_heightmap`, as in vanilla. That includes slabs, stairs, fences, walls, glass panes, beds and other blocks that aren't a full cube. Before, rain fell through a slab roof. - Roofs higher than 20 blocks above the player also stop rain. Before, the downward walk started 10 blocks above the weather box, so a roof higher than that was not seen. The rain sound tick and the splash particles use the same height. ## Numbers Same scene for both builds: seed 1234, the village at (-960, 90, 150) for clear and rain, snowy plains at (-1216, 90, 438) for snow. Mobs off and killed, standing still, `horizon-ctl bench` 5 s, conditions alternated within one game, medians. **Mac mini (M4 Pro), macOS, Metal**, offscreen 1280x720, 8 runs per row. Both builds include #1079 (stars), so they differ only by this PR's commit. They ran in the order before, after, after, before. CI runners were loading the machine (load 32–64; the last "before" game ran at 64), which is why clear weather wanders. The `prepare` phase is the figure to read: | | before | this PR | |---|---:|---:| | clear: CPU frame / FPS | 1.065 ms / 874 | 1.063 ms / 856 | | rain: CPU frame / FPS | 1.703 ms / 561 | **1.163 ms / 759** | | snow: CPU frame / FPS | 1.440 ms / 663 | **0.917 ms / 981** | | `prepare`, rain | 0.869 ms | **0.383 ms** | | `prepare`, snow | 0.786 ms | **0.349 ms** | **ThinkPad, Intel HD 620**, Linux, Mesa Vulkan, offscreen 1280x720, nice 19, 8 runs per row (clear is within run-to-run noise): | | main CPU | this PR CPU | main FPS | this PR FPS | |---|---:|---:|---:|---:| | clear | 2.264 ms | 2.452 ms | 274 | 267 | | rain | 4.771 ms | **3.520 ms** | 128 | 127 | | snow | 4.123 ms | **3.136 ms** | 160 | 158 | | `prepare` phase, rain | 1.922 ms | **0.901 ms** | | | The HD 620 is GPU-bound in rain, at 7.5 ms of GPU per frame against 3.3 ms in clear weather, so its FPS doesn't move. That GPU cost is the overdraw of the rain columns with vanilla's weather pipeline (depth write, blend, discard), and it is the same on both builds. **Desktop, RTX 4080**, Linux, Vulkan, offscreen 1280x720 (round 1 of 2; round 2 overlapped my own test run): | | main | this PR | |---|---:|---:| | clear | 2952 FPS | 2939 FPS | | rain | 1182 FPS (0.847 ms) | **2125 FPS (0.470 ms)** | | snow | 1248 FPS | **2105 FPS** | | `prepare`, rain | 0.506 ms | 0.207 ms | ## Screenshots In rain, on the ThinkPad, with the same seed and the same commands for both builds. Two roofs are placed three blocks above the ground: oak slabs on the left and oak planks on the right. Standing under the slabs and looking up. On main, rain falls through the slab roof. With this PR it stops on the slabs, as in vanilla: | main | this PR | |---|---| | ![main, under slabs](https://raw.githubusercontent.com/ludovic111/horizon/71bab0ac9ad69eeaf365fcc098f1735a0c147645/weather/base-under-slabs.png) | ![this PR, under slabs](https://raw.githubusercontent.com/ludovic111/horizon/71bab0ac9ad69eeaf365fcc098f1735a0c147645/weather/weather-under-slabs.png) | The wider view looks the same on both: | main | this PR | |---|---| | ![main, rain](https://raw.githubusercontent.com/ludovic111/horizon/71bab0ac9ad69eeaf365fcc098f1735a0c147645/weather/base-rain.png) | ![this PR, rain](https://raw.githubusercontent.com/ludovic111/horizon/71bab0ac9ad69eeaf365fcc098f1735a0c147645/weather/weather-rain.png) | ## Checks - `cargo fmt --all --check`: clean. - `cargo clippy -p horizon-client --all-targets -- -D warnings` with `set -o pipefail`: exit 0. This is scoped to the touched crate because workspace-wide clippy fails on that machine on hidapi/libudev, which this PR doesn't touch. - `cargo test -p horizon-client`: all pass (lib 942, plus the integration tests). New tests: `motion_blocking_follows_writes` and `pieces_cut_at_whole_numbers`. - `tools/parity.py --changed origin/main` lists every harness (none has a pass history yet), so I ran the ones this touches, `weather_render`, `heightmap`, `biome_weather` and `environment_render`, on the desktop. On main at bc890421 all 4 pass. On bc890421 with this PR and #1079 all 4 pass. 🤖 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-02 16:00:57 +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#3033
No description provided.