[PR #1237] [MERGED] Cache rain/snow column parameters and animate atlas UVs in shader #3443

Closed
opened 2026-11-03 04:09:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/cache-rain-snow-params-157e7038


📝 Commits (2)

  • e4ea9e0 Cache weather column parameters and animate atlas UVs in shader
  • 5d77ace Merge main into #1237: keep #1234's column table and #1238's bolt quads

📊 Changes

7 files changed (+808 additions, -66 deletions)

View changed files

📝 crates/horizon-client/examples/weather_fixture.rs (+8 -0)
📝 crates/horizon-client/src/entity.wgsl (+133 -0)
📝 crates/horizon-client/src/game.rs (+61 -59)
📝 crates/horizon-client/src/gfx.rs (+23 -1)
➕ crates/horizon-client/src/gfx/weather.rs (+330 -0)
📝 crates/horizon-client/src/weather.rs (+251 -4)
📝 tools/test_weather_render_parity.py (+2 -2)

📄 Description

What and why

Rendering precipitation currently recreates each column's seeded random source every frame, including snow's Gaussian draws, then splits the animated UV range into atlas-sized pieces. Cache the coordinate-only random parameters in a fixed 1024-entry direct-mapped cache and render one quad per column, with UV animation and atlas-local nearest-repeat sampling in the shader.

Height, precipitation/temperature, light, camera geometry/fade, radius and atlas rectangles are still sampled each frame. The cache contains no world or resource references, so biome, dimension and resource reloads cannot leave stale world-dependent values. Full coordinate keys handle cache collisions and teleports. Masked tick values preserve negative/large ticks and both animation wraps; integer shader arithmetic retains snow's double-precision random bases and double-to-float rounding without requiring GPU float64. Rain-before-snow ordering and the existing render position are retained. Invalid radii are bounded by the existing direction table, and coordinate arithmetic avoids overflow at integer limits.

The cached MOTION_BLOCKING heightmaps and allocation-free reference tiling from #1084 are retained. column_size is untouched. The original public random-source helpers and fixture output remain intact; the fixture additionally asserts cached-parameter parity. The shader and renderer integration plus differential coverage are one coupled optimisation, so this PR keeps the work in one issue despite the self-check's size warning.

Vanilla reference

net.minecraft.client.renderer.WeatherEffectRenderer: extractRenderState, createRainColumnInstance, createSnowColumnInstance, and prepareInstances. In particular, snow adds a double random base to a float drift before casting to float; rounding that base early is not equivalent.

Validation

  • python tools/test_weather_render_parity.py: 881 cases byte-identical to pinned Minecraft 26.3, including negative/maximum ticks, both wrap boundaries, large coordinates and integer-limit coordinates. Cached parameters are checked against the original random-source path for each case.
  • cargo test --locked -p horizon-client --lib weather -- --include-ignored --nocapture: production WGSL executed on an NVIDIA RTX 4060/Vulkan; 57,393 UV and atlas texel cases matched bit for bit, including double-rounding midpoints and cancellation. CPU tests also cover cache reuse/collisions/bounds and changing geometry/light/atlas inputs.
  • cargo test --locked -p horizon-client --lib gfx::tests:: -- --nocapture: 14 passed, including WGSL validation and translation of all shaders to HLSL.
  • cargo check --locked -p horizon-client --no-default-features --bin horizon-client: passed.
  • Offscreen rendered rain smoke run using prepared resources, test terrain, render distance 2 and 8 world frames: 9 total frames, error: null, including real pipeline creation and frame submission.

These checks establish CPU column/quad and GPU UV/atlas-sampling parity, not pixel-for-pixel framebuffer parity. The unsplit quad uses vanilla's four-corner interpolation; fog and optional dynamic-light interpolation can differ from the subdivisions introduced by the previous atlas tiling. Native GPU validation here covers Vulkan; DirectX 12 has shader translation coverage. No frame-time or FPS improvement is claimed, and the broader automatically selected parity suite was not run (--quick).

Self-check

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at 34c3c1cff, 1 min 21 s)

Check Result
Scope ⚠️ 7 files, +809 −67; 872 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 290 passed (22 s)
rustfmt ✅ (6 s)
clippy ✅ (18 s)
tests: horizon-client ✅ 1111 passed (28 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 279 affected, to run in CI (--quick): ambient_sound, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo, basic_feature, biome_chunk, biome_generation and 267 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 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/1237 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/cache-rain-snow-params-157e7038` --- ### 📝 Commits (2) - [`e4ea9e0`](https://github.com/horizon-rust/horizon/commit/e4ea9e0199d3a2bbf4f99aa761e212b2bb897ca9) Cache weather column parameters and animate atlas UVs in shader - [`5d77ace`](https://github.com/horizon-rust/horizon/commit/5d77ace9a4c1fd1b07326b471090085b3c7102dd) Merge main into #1237: keep #1234's column table and #1238's bolt quads ### 📊 Changes **7 files changed** (+808 additions, -66 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/weather_fixture.rs` (+8 -0) 📝 `crates/horizon-client/src/entity.wgsl` (+133 -0) 📝 `crates/horizon-client/src/game.rs` (+61 -59) 📝 `crates/horizon-client/src/gfx.rs` (+23 -1) ➕ `crates/horizon-client/src/gfx/weather.rs` (+330 -0) 📝 `crates/horizon-client/src/weather.rs` (+251 -4) 📝 `tools/test_weather_render_parity.py` (+2 -2) </details> ### 📄 Description ## What and why Rendering precipitation currently recreates each column's seeded random source every frame, including snow's Gaussian draws, then splits the animated UV range into atlas-sized pieces. Cache the coordinate-only random parameters in a fixed 1024-entry direct-mapped cache and render one quad per column, with UV animation and atlas-local nearest-repeat sampling in the shader. Height, precipitation/temperature, light, camera geometry/fade, radius and atlas rectangles are still sampled each frame. The cache contains no world or resource references, so biome, dimension and resource reloads cannot leave stale world-dependent values. Full coordinate keys handle cache collisions and teleports. Masked tick values preserve negative/large ticks and both animation wraps; integer shader arithmetic retains snow's double-precision random bases and double-to-float rounding without requiring GPU float64. Rain-before-snow ordering and the existing render position are retained. Invalid radii are bounded by the existing direction table, and coordinate arithmetic avoids overflow at integer limits. The cached MOTION_BLOCKING heightmaps and allocation-free reference tiling from #1084 are retained. `column_size` is untouched. The original public random-source helpers and fixture output remain intact; the fixture additionally asserts cached-parameter parity. The shader and renderer integration plus differential coverage are one coupled optimisation, so this PR keeps the work in one issue despite the self-check's size warning. ## Vanilla reference `net.minecraft.client.renderer.WeatherEffectRenderer`: `extractRenderState`, `createRainColumnInstance`, `createSnowColumnInstance`, and `prepareInstances`. In particular, snow adds a double random base to a float drift before casting to float; rounding that base early is not equivalent. ## Validation - `python tools/test_weather_render_parity.py`: **881 cases byte-identical to pinned Minecraft 26.3**, including negative/maximum ticks, both wrap boundaries, large coordinates and integer-limit coordinates. Cached parameters are checked against the original random-source path for each case. - `cargo test --locked -p horizon-client --lib weather -- --include-ignored --nocapture`: production WGSL executed on an NVIDIA RTX 4060/Vulkan; **57,393 UV and atlas texel cases matched bit for bit**, including double-rounding midpoints and cancellation. CPU tests also cover cache reuse/collisions/bounds and changing geometry/light/atlas inputs. - `cargo test --locked -p horizon-client --lib gfx::tests:: -- --nocapture`: **14 passed**, including WGSL validation and translation of all shaders to HLSL. - `cargo check --locked -p horizon-client --no-default-features --bin horizon-client`: passed. - Offscreen rendered rain smoke run using prepared resources, test terrain, render distance 2 and 8 world frames: **9 total frames, `error: null`**, including real pipeline creation and frame submission. These checks establish CPU column/quad and GPU UV/atlas-sampling parity, not pixel-for-pixel framebuffer parity. The unsplit quad uses vanilla's four-corner interpolation; fog and optional dynamic-light interpolation can differ from the subdivisions introduced by the previous atlas tiling. Native GPU validation here covers Vulkan; DirectX 12 has shader translation coverage. No frame-time or FPS improvement is claimed, and the broader automatically selected parity suite was not run (`--quick`). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at 34c3c1cff, 1 min 21 s) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +809 −67; 872 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 290 passed (22 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (18 s) | | tests: horizon-client | ✅ 1111 passed (28 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 279 affected, to run in CI (--quick): ambient_sound, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo, basic_feature, biome_chunk, biome_generation and 267 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:09:34 +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#3443
No description provided.