[PR #4379] [MERGED] Shader API: the material stage's water mirror #5591

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4379
Author: @Teiwazik
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: shader/s5-water-mirror


📝 Commits (10+)

  • fa845cd Shader API: the material stage sees what lies behind translucent terrain
  • 951c7d5 Shader API: the frame's motion since the last one, and the eye's light eased
  • 07d3026 Shader API: the post stage's history, last frame's input to the last pass
  • f9ef4e0 Shader API: the material stage's face, fluid, emission, normal and tangent
  • 9b53e24 Shader API: the material stage's water mirror
  • 45d19d1 Merge remote-tracking branch 'origin/main' into shader/s5-water-mirror
  • 3dbcf3c Merge remote-tracking branch 'origin/main' into pr4335
  • 252ac76 Merge branch 'pr4335' into pr4345
  • ff2bf4e Merge branch 'shader/s2-frame-motion' into shader/s3-post-history
  • f8184ab Merge branch 'shader/s3-post-history' into shader/s4-material-surface

📊 Changes

20 files changed (+1171 additions, -57 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+303 -6)
📝 crates/horizon-client-render/src/gfx/flat.rs (+15 -2)
📝 crates/horizon-client-render/src/gfx/native_material.rs (+28 -2)
📝 crates/horizon-client-render/src/gfx/native_pack.rs (+6 -1)
📝 crates/horizon-client-render/src/gfx/native_post.rs (+456 -20)
📝 crates/horizon-client-render/src/gfx/resident.rs (+5 -3)
📝 crates/horizon-client-render/src/gfx/world_post.rs (+5 -2)
📝 crates/horizon-client-render/src/lod/mesh.rs (+9 -2)
📝 crates/horizon-client-render/src/mesher.rs (+43 -1)
📝 crates/horizon-client-render/src/mesher/fluid.rs (+18 -9)
📝 crates/horizon-client-render/src/terrain.wgsl (+12 -0)
📝 crates/horizon-client/examples/probe/section_mesh_fixture.rs (+2 -2)
📝 crates/horizon-client/src/game.rs (+18 -0)
📝 crates/horizon-client/src/game/boats.rs (+57 -0)
📝 crates/horizon-shader-api/src/check.rs (+20 -0)
📝 crates/horizon-shader-api/src/inputs.rs (+32 -2)
📝 crates/horizon-shader-api/src/stages.rs (+86 -5)
📝 crates/horizon-shader-api/tests/check.rs (+21 -0)
📝 docs/api/shaders-reference.md (+20 -0)
📝 docs/api/shaders.md (+15 -0)

📄 Description

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

Fixes #4378

Builds on #4359 (and #4349, #4345, #4335 under it); this PR's own change is the last commit (15 files, +493 −16, the regenerated reference included).

What and why

  • The material prelude gains reflection (binding 1) and reflection_sampler (binding 2): the world as a camera mirrored about the horizontal water plane around the camera sees it. It holds the sky and solid terrain at half the world's resolution, mapped like the world's picture, so water samples it at input.screen. Frame gains water_plane, has_reflection and reflection_resolution (16 bytes, so Frame stays a multiple of 16).
  • Cost only for packs that use it:
    • The mirror is drawn only for a pack whose material function, or a function it calls, reads reflection. The new CheckedStage::reads finds that through naga's global uses.
    • Other packs and vanilla draw nothing extra.
    • The game looks for the plane only for such a pack (Renderer::wants_water_plane).
  • The plane (Game::water_plane, in boats.rs beside fluid_height) is the median standing-water surface of a grid of columns 48 blocks around the camera:
    • it is scanned again when the camera changes block, or each second;
    • a plane in use stays while a quarter of the columns are still on it, so two lakes at different heights do not make the mirror flicker;
    • with no water in reach, the last plane stays.
  • The mirror pass:
    • draws the vanilla sky and the solid terrain lists with the mirrored view-projection, into its own target;
    • uses fs_solid_mirror (terrain.wgsl, and the flat draws' pipeline), which cuts away what lies below the plane, passed in fog_ends.w of the mirror's own globals;
    • culls the front faces, since the mirror flips the winding.
  • Culling:
    • Sections are culled against the union of the camera's and the mirror's frusta (Frusta, Cull in Resident::visible), so trees above the top of the picture still reflect.
    • While mirroring, solid quads are not left out by facing, because the mirror's eye sees the undersides. Occlusion culling is off too: both follow the camera's eye. A follow-up can restore facing culling for the eyes between the camera and its mirror.

Tests:

  • the_mirror_sees_each_point_where_its_reflection_is: the mirrored view-projection;
  • reads_follows_the_stage_function_through_its_calls;
  • the renderer's material test shader now samples reflection.

Checked in game with a test pack whose water shows only reflection: a pond shows the sky and its shore upside down.

pr_ready

pr_ready (tools/pr_ready.py --quick on Teiwazik, against origin/main at 68f036059, 3 min 28 s)

Check Result
Scope ⚠️ 19 files, +1041 −48; 1033 lines of code: over 500, split it if it can ship in parts (the stack under it; this PR's own commit is +493 −16)
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 18 s)
rustfmt ✅ (13 s)
clippy ✅ (35 s)
tests: horizon-client, horizon-client-render, horizon-shader-api ❌ 726 passed, 1 failed (1 min 14 s): title::tests::each_world_preset_writes_its_own_generator, which fails on Windows on main too (a world folder name with :), untouched here
doc tests ✅ 0 passed (5 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/4379 **Author:** [@Teiwazik](https://github.com/Teiwazik) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `shader/s5-water-mirror` --- ### 📝 Commits (10+) - [`fa845cd`](https://github.com/horizon-rust/horizon/commit/fa845cd5802713d4824f42f296eaf99b52792dd8) Shader API: the material stage sees what lies behind translucent terrain - [`951c7d5`](https://github.com/horizon-rust/horizon/commit/951c7d5165d02d68f47d89fb1f2033efd5b9b6c0) Shader API: the frame's motion since the last one, and the eye's light eased - [`07d3026`](https://github.com/horizon-rust/horizon/commit/07d302639ecb87e90e0127669cdc54adaff8d98f) Shader API: the post stage's history, last frame's input to the last pass - [`f9ef4e0`](https://github.com/horizon-rust/horizon/commit/f9ef4e0ea0dd0ab14ff52392cf792c3706bc774f) Shader API: the material stage's face, fluid, emission, normal and tangent - [`9b53e24`](https://github.com/horizon-rust/horizon/commit/9b53e24b33135aee408b8b91f18d8b1b40fe7928) Shader API: the material stage's water mirror - [`45d19d1`](https://github.com/horizon-rust/horizon/commit/45d19d1f8787a830f4e1d17135f80cd81db815cb) Merge remote-tracking branch 'origin/main' into shader/s5-water-mirror - [`3dbcf3c`](https://github.com/horizon-rust/horizon/commit/3dbcf3c6c66104f76353df7352d14d12889409ec) Merge remote-tracking branch 'origin/main' into pr4335 - [`252ac76`](https://github.com/horizon-rust/horizon/commit/252ac76369990b6ef98615f6a125d769ec407707) Merge branch 'pr4335' into pr4345 - [`ff2bf4e`](https://github.com/horizon-rust/horizon/commit/ff2bf4e6706e9f107da0fb8c2c2587216c985356) Merge branch 'shader/s2-frame-motion' into shader/s3-post-history - [`f8184ab`](https://github.com/horizon-rust/horizon/commit/f8184ab1fb0aa8f3df1e5c779f5a9d980e852340) Merge branch 'shader/s3-post-history' into shader/s4-material-surface ### 📊 Changes **20 files changed** (+1171 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+303 -6) 📝 `crates/horizon-client-render/src/gfx/flat.rs` (+15 -2) 📝 `crates/horizon-client-render/src/gfx/native_material.rs` (+28 -2) 📝 `crates/horizon-client-render/src/gfx/native_pack.rs` (+6 -1) 📝 `crates/horizon-client-render/src/gfx/native_post.rs` (+456 -20) 📝 `crates/horizon-client-render/src/gfx/resident.rs` (+5 -3) 📝 `crates/horizon-client-render/src/gfx/world_post.rs` (+5 -2) 📝 `crates/horizon-client-render/src/lod/mesh.rs` (+9 -2) 📝 `crates/horizon-client-render/src/mesher.rs` (+43 -1) 📝 `crates/horizon-client-render/src/mesher/fluid.rs` (+18 -9) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+12 -0) 📝 `crates/horizon-client/examples/probe/section_mesh_fixture.rs` (+2 -2) 📝 `crates/horizon-client/src/game.rs` (+18 -0) 📝 `crates/horizon-client/src/game/boats.rs` (+57 -0) 📝 `crates/horizon-shader-api/src/check.rs` (+20 -0) 📝 `crates/horizon-shader-api/src/inputs.rs` (+32 -2) 📝 `crates/horizon-shader-api/src/stages.rs` (+86 -5) 📝 `crates/horizon-shader-api/tests/check.rs` (+21 -0) 📝 `docs/api/shaders-reference.md` (+20 -0) 📝 `docs/api/shaders.md` (+15 -0) </details> ### 📄 Description > 🤖 Opened by Teiwazik's AI agent (Claude Code, Claude Opus 5.5), not by Teiwazik personally. Fixes #4378 Builds on #4359 (and #4349, #4345, #4335 under it); this PR's own change is the last commit (15 files, +493 −16, the regenerated reference included). ## What and why - The material prelude gains `reflection` (binding 1) and `reflection_sampler` (binding 2): the world as a camera mirrored about the horizontal water plane around the camera sees it. It holds the sky and solid terrain at half the world's resolution, mapped like the world's picture, so water samples it at `input.screen`. `Frame` gains `water_plane`, `has_reflection` and `reflection_resolution` (16 bytes, so `Frame` stays a multiple of 16). - Cost only for packs that use it: - The mirror is drawn only for a pack whose `material` function, or a function it calls, reads `reflection`. The new `CheckedStage::reads` finds that through naga's global uses. - Other packs and vanilla draw nothing extra. - The game looks for the plane only for such a pack (`Renderer::wants_water_plane`). - The plane (`Game::water_plane`, in `boats.rs` beside `fluid_height`) is the median standing-water surface of a grid of columns 48 blocks around the camera: - it is scanned again when the camera changes block, or each second; - a plane in use stays while a quarter of the columns are still on it, so two lakes at different heights do not make the mirror flicker; - with no water in reach, the last plane stays. - The mirror pass: - draws the vanilla sky and the solid terrain lists with the mirrored view-projection, into its own target; - uses `fs_solid_mirror` (terrain.wgsl, and the flat draws' pipeline), which cuts away what lies below the plane, passed in `fog_ends.w` of the mirror's own globals; - culls the front faces, since the mirror flips the winding. - Culling: - Sections are culled against the union of the camera's and the mirror's frusta (`Frusta`, `Cull` in `Resident::visible`), so trees above the top of the picture still reflect. - While mirroring, solid quads are not left out by facing, because the mirror's eye sees the undersides. Occlusion culling is off too: both follow the camera's eye. A follow-up can restore facing culling for the eyes between the camera and its mirror. Tests: - `the_mirror_sees_each_point_where_its_reflection_is`: the mirrored view-projection; - `reads_follows_the_stage_function_through_its_calls`; - the renderer's material test shader now samples `reflection`. Checked in game with a test pack whose water shows only `reflection`: a pond shows the sky and its shore upside down. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on Teiwazik, against origin/main at 68f036059, 3 min 28 s) | Check | Result | | --- | --- | | Scope | ⚠️ 19 files, +1041 −48; 1033 lines of code: over 500, split it if it can ship in parts (the stack under it; this PR's own commit is +493 −16) | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 18 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (35 s) | | tests: horizon-client, horizon-client-render, horizon-shader-api | ❌ 726 passed, 1 failed (1 min 14 s): `title::tests::each_world_preset_writes_its_own_generator`, which fails on Windows on main too (a world folder name with `:`), untouched here | | doc tests | ✅ 0 passed (5 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:13:37 +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#5591
No description provided.