[PR #2122] [MERGED] Horizon shader packs: the material stage runs in the game #4024

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

📋 Pull Request Information

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

Base: main ← Head: feat/native-material-stage


📝 Commits (2)

  • c813261 Horizon shader packs: the material stage runs in the game
  • 68fa771 Merge remote-tracking branch 'origin/main' into feat/native-material-stage

📊 Changes

5 files changed (+396 additions, -31 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+39 -17)
➕ crates/horizon-client/src/gfx/native_material.rs (+328 -0)
📝 crates/horizon-client/src/gfx/native_pack.rs (+19 -5)
📝 docs/api/shaders.md (+3 -2)
📝 docs/shaders.md (+7 -7)

📄 Description

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

Builds on #2112 (the shared WGSL prefixer, merged).

What pack authors can do now

A Horizon shader pack's [material] stage runs in the game. fn material(input: MaterialInput) -> Surface returns the lit colour of every point of terrain: sections and distant tiles; solid, cutout and translucent (water, glass, ice); in the instanced draws and in the flat ones. Horizon then applies the alpha test and fog, as vanilla does. The input has what vanilla multiplies together, kept apart: the texture's colour (albedo), the vertex tint (biome, face shade, ambient occlusion), the block and sky light levels (0..1), the lightmap's colour for them, the camera-relative position, the atlas UV, and whether the surface is translucent. Entities, block entities and particles keep vanilla's look. Like the other stages, the pack is picked on the Shader Packs page and hot-reloads.

How

Terrain still draws with Horizon's meshes, culling and draw lists; only its pipelines change.

  • gfx/native_material.rs: the shader is the pack's checked stage (CheckedStage::source), then terrain.wgsl's terrain section with every name prefixed horizon_terrain_ (wgsl_prefix.rs), then four entries:
    • horizon_material_vs and horizon_material_vs_flat do vanilla's vertex work but keep the tint and the lightmap's colour apart, and pass the light levels, the position and the fog distances.
    • horizon_material_fs_solid and horizon_material_fs_translucent sample the texture, call material, then run fs_solid's and fs_translucent's alpha test and fog.
  • Pipelines: the same states as the renderer's terrain (back faces culled, reversed depth, alpha blending for translucent). They read group 0 (terrain), group 1 (flat draws, where they run) and group 3 (the pack's frame), with SPRITE_ARRAYS/SPRITE_SPLIT as the renderer sets them.
  • gfx.rs: the world pass picks the pack's solid and translucent pipelines (instanced and flat) when the pack has a material, and binds its frame at group 3, also after occlusion culling's second pass. Without a pack, the same pipelines and calls as before.
  • NativePack builds the material beside the sky and post stages. On an error, the pack that ran keeps running.
  • Docs: shaders.md (status, what the material covers, F3: the material has no pass of its own), api/shaders.md changelog.

Evidence

In the game: offscreen, Metal, the same seed and view, isolated dirs. Screenshots are in ~/code/horizon-parity/screenshots/shaders-api-2/:

  • material-off.png: no pack.
  • material-faded.png: a test pack whose material greys vanilla's lit colour (saturation 0.25) and warms it where block light reaches. Leaves, grass, water and the mushroom block turn grey; the hand (an entity), the sky and the clouds don't change.
  • material-same.png: a pass-through pack (albedo * tint * vec4(lightmap, 1.0), vanilla's own). Against no pack, 97 % of the 198 682 channel values that differ are off by 1 or 2 out of 255. The pack gets the tint and the lightmap interpolated apart, while vanilla interpolates their product. 5 661 channel values differ by more than 2; two no-pack runs of the same view differ in 2 258, from moving water and the hand.

Test the_terrain_takes_a_prefix_and_validates_with_a_pack: the combined module passes naga validation with a pack that declares its own sprite, apply_fog and PI, and it has the four entries.

A/B (paired, alternating, 3 rounds of horizon-ctl bench 15, offscreen, render distance 12; the machine was busy):

CPU ms (rounds) mean GPU ms mean
base (#2112), no pack 0.720 0.771 0.768 0.753 1.991
this PR, no pack 0.733 0.745 0.733 0.737 1.922
this PR, pass-through material pack 0.864 0.868 0.845 0.859 2.191

No cost without a pack. With one, the GPU adds about 0.27 ms for terrain's longer shader. On the CPU, any running pack costs about 0.1 ms: its frame uniform and the twice-a-second reload check, as with the post and sky stages.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 4fbb0cde7, 6 min 24 s)

Check Result
Scope ✅ 5 files, +396 −31
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (8 s)
clippy ✅ (2 min 7 s)
tests: horizon-client ✅ 1301 passed (3 min 23 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 32 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, friends_integration, hardcore_respawn, lan_integration, locator_bar, mace and 20 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

This is the head after merging main: the docs/shaders.md status table and its Next section conflicted with #2036.

Harnesses (tools/parity.py --changed origin/main, the set --changed-files picks for these files): 33 passed, 0 failed at 68fa7714b. Before the merge with main: 32 passed at c81326157.

🤖 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/2122 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/native-material-stage` --- ### 📝 Commits (2) - [`c813261`](https://github.com/horizon-rust/horizon/commit/c8132615742b62170412feae5aab463ca46f7168) Horizon shader packs: the material stage runs in the game - [`68fa771`](https://github.com/horizon-rust/horizon/commit/68fa7714bb2a2ac111510722dde9fe74f49d8cc9) Merge remote-tracking branch 'origin/main' into feat/native-material-stage ### 📊 Changes **5 files changed** (+396 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+39 -17) ➕ `crates/horizon-client/src/gfx/native_material.rs` (+328 -0) 📝 `crates/horizon-client/src/gfx/native_pack.rs` (+19 -5) 📝 `docs/api/shaders.md` (+3 -2) 📝 `docs/shaders.md` (+7 -7) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Builds on #2112 (the shared WGSL prefixer, merged). ## What pack authors can do now A Horizon shader pack's `[material]` stage runs in the game. `fn material(input: MaterialInput) -> Surface` returns the lit colour of every point of terrain: sections and distant tiles; solid, cutout and translucent (water, glass, ice); in the instanced draws and in the flat ones. Horizon then applies the alpha test and fog, as vanilla does. The input has what vanilla multiplies together, kept apart: the texture's colour (`albedo`), the vertex tint (biome, face shade, ambient occlusion), the block and sky light levels (0..1), the lightmap's colour for them, the camera-relative position, the atlas UV, and whether the surface is translucent. Entities, block entities and particles keep vanilla's look. Like the other stages, the pack is picked on the Shader Packs page and hot-reloads. ## How Terrain still draws with Horizon's meshes, culling and draw lists; only its pipelines change. - `gfx/native_material.rs`: the shader is the pack's checked stage (`CheckedStage::source`), then terrain.wgsl's terrain section with every name prefixed `horizon_terrain_` (`wgsl_prefix.rs`), then four entries: - `horizon_material_vs` and `horizon_material_vs_flat` do vanilla's vertex work but keep the tint and the lightmap's colour apart, and pass the light levels, the position and the fog distances. - `horizon_material_fs_solid` and `horizon_material_fs_translucent` sample the texture, call `material`, then run `fs_solid`'s and `fs_translucent`'s alpha test and fog. - Pipelines: the same states as the renderer's terrain (back faces culled, reversed depth, alpha blending for translucent). They read group 0 (terrain), group 1 (flat draws, where they run) and group 3 (the pack's `frame`), with `SPRITE_ARRAYS`/`SPRITE_SPLIT` as the renderer sets them. - `gfx.rs`: the world pass picks the pack's solid and translucent pipelines (instanced and flat) when the pack has a material, and binds its frame at group 3, also after occlusion culling's second pass. Without a pack, the same pipelines and calls as before. - `NativePack` builds the material beside the sky and post stages. On an error, the pack that ran keeps running. - Docs: shaders.md (status, what the material covers, F3: the material has no pass of its own), api/shaders.md changelog. ## Evidence In the game: offscreen, Metal, the same seed and view, isolated dirs. Screenshots are in `~/code/horizon-parity/screenshots/shaders-api-2/`: - `material-off.png`: no pack. - `material-faded.png`: a test pack whose material greys vanilla's lit colour (saturation 0.25) and warms it where block light reaches. Leaves, grass, water and the mushroom block turn grey; the hand (an entity), the sky and the clouds don't change. - `material-same.png`: a pass-through pack (`albedo * tint * vec4(lightmap, 1.0)`, vanilla's own). Against no pack, 97 % of the 198 682 channel values that differ are off by 1 or 2 out of 255. The pack gets the tint and the lightmap interpolated apart, while vanilla interpolates their product. 5 661 channel values differ by more than 2; two no-pack runs of the same view differ in 2 258, from moving water and the hand. Test `the_terrain_takes_a_prefix_and_validates_with_a_pack`: the combined module passes naga validation with a pack that declares its own `sprite`, `apply_fog` and `PI`, and it has the four entries. A/B (paired, alternating, 3 rounds of `horizon-ctl bench 15`, offscreen, render distance 12; the machine was busy): | | CPU ms (rounds) | mean | GPU ms mean | |---|---|---|---| | base (#2112), no pack | 0.720 0.771 0.768 | 0.753 | 1.991 | | this PR, no pack | 0.733 0.745 0.733 | 0.737 | 1.922 | | this PR, pass-through material pack | 0.864 0.868 0.845 | 0.859 | 2.191 | No cost without a pack. With one, the GPU adds about 0.27 ms for terrain's longer shader. On the CPU, any running pack costs about 0.1 ms: its frame uniform and the twice-a-second reload check, as with the post and sky stages. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 4fbb0cde7, 6 min 24 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +396 −31 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (8 s) | | clippy | ✅ (2 min 7 s) | | tests: horizon-client | ✅ 1301 passed (3 min 23 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 32 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, friends_integration, hardcore_respawn, lan_integration, locator_bar, mace and 20 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | This is the head after merging main: the docs/shaders.md status table and its Next section conflicted with #2036. Harnesses (`tools/parity.py --changed origin/main`, the set `--changed-files` picks for these files): **33 passed, 0 failed** at 68fa7714b. Before the merge with main: 32 passed at c81326157. 🤖 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 04:14:05 +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#4024
No description provided.