[PR #1261] [CLOSED] Horizon shaders v1: shadow maps, world hooks, G-buffer, deferred stages, compiled stages #3464

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1261
Author: @ludovic111
Created: 10/22/2026
Status: ❌ Closed

Base: main ← Head: feat/horizon-shaders-v1


📝 Commits (1)

  • 7b06970 Horizon shaders v1: shadow maps, world hooks, G-buffer, deferred stages

📊 Changes

18 files changed (+3320 additions, -298 deletions)

View changed files

📝 Cargo.lock (+1 -0)
📝 crates/horizon-client/Cargo.toml (+2 -2)
📝 crates/horizon-client/src/entity.wgsl (+4 -0)
📝 crates/horizon-client/src/game/shader_packs.rs (+13 -2)
📝 crates/horizon-client/src/gfx.rs (+456 -56)
📝 crates/horizon-client/src/gfx/cull.rs (+68 -37)
📝 crates/horizon-client/src/gfx/flat.rs (+4 -0)
📝 crates/horizon-client/src/gfx/pack_stages.rs (+498 -143)
➕ crates/horizon-client/src/gfx/pack_world.rs (+738 -0)
📝 crates/horizon-client/src/gfx/world_post.rs (+18 -7)
📝 crates/horizon-client/src/shader_pack.rs (+890 -19)
➕ crates/horizon-client/src/shader_pack_common.wgsl (+101 -0)
➕ crates/horizon-client/src/shader_pack_entity.wgsl (+73 -0)
📝 crates/horizon-client/src/shader_pack_prelude.wgsl (+43 -27)
➕ crates/horizon-client/src/shader_pack_terrain.wgsl (+129 -0)
➕ crates/horizon-client/src/shader_pack_world.wgsl (+69 -0)
📝 crates/horizon-client/src/terrain.wgsl (+5 -1)
📝 docs/shader-packs.md (+208 -4)

📄 Description

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

First of the "Horizon shaders v1" PRs (brief shaders-1). This one is the runtime; the stacked PR on top (#1262) adds the Rust SDK, cargo horizon-shader and the Daybreak example pack. The options page is a separate, independent PR (#1260).

Decision: Rust (rust-gpu) for stages, WGSL for world hooks

  • Full-screen stages can be written in Rust with rust-gpu. A pack ships the compiled .spv; the game reads it with naga (spv-in), validates it and writes it back as WGSL, so wgpu treats it like any stage and it reaches Metal, Vulkan and DirectX 12 the same way. Players need no toolchain. Checked: Daybreak's five Rust stages translate to MSL, HLSL and SPIR-V in tests, and render the same on Metal (M4 Pro) and Vulkan (RTX 4080).
  • World hooks stay WGSL in v1: rust-gpu emits entry points, while a hook is a function Horizon composes into its own terrain/entity/sky shaders. Rust hooks need a pass lifting functions out of the compiled module through naga IR (FEATURES.md LATER).
  • Costs, written in the docs: option names don't survive rust-gpu (specialization constants are numbered), so options a Rust stage reads carry an id; SPIR-V can't hold images or samplers in structs, so the SDK passes resources one by one. The first cargo gpu build installs its pinned nightly (about 12 min on the M4 Pro), later builds take 2-4 s.

What api 2 adds (docs/shader-packs.md, "Horizon shaders v1")

  • [shadow]: a shadow map from the sun (the moon at night), sections within distance culled with the light's frustum, the box moving in whole texels (depth too), distortion towards the player, 4-tap PCF via shadow_lit(). The shadow pass is skipped while its map is still right (same light step of about 0.015°, same texel box, same casters, no terrain upload since), so a still player redraws it a few times a second instead of every frame.
  • [gbuffer]: WGSL hooks surface_vertex, surface_normal, surface_color, sky_color, composed into Horizon's terrain, entity and sky shaders, with defaults for any a pack leaves out. Opaque and translucent surfaces write colour plus an Rgba16Uint G-buffer (octahedral normal, block/sky light, material). Flags for vanilla's sun/moon, stars and clouds.
  • deferred stages between opaque and translucent geometry; the opaque depth for stages; [[target]] (6 formats, scale, history for last frame), [[texture]] PNGs, [materials] ids 16-255 by sprite glob on top of Horizon's 9 (terrain, leaves, plants, water, lava, glass, emissive, entity).
  • Frame grows (previous view-projection, shadow matrix, camera delta, shadow settings, light direction, world size); the api 1 layout is unchanged in front.
  • No pack: no change. None of the new passes, targets or pipelines exist without a pack; an api 1 pack draws as before (the world pass is split only when a pack has [gbuffer]).

Frame times (1280x720, same scene: seed 42, (-30,100,0) yaw 270 pitch 25, noon, spectator)

bench 20 with the frame limit off, two runs each, p50 frame time, --profile fast builds of this branch. "Flying" is fly over 80 blocks in 20 s with the daylight cycle on (chunks load, the sun moves, the shadow map redraws).

M4 Pro (Metal) still M4 Pro flying RTX 4080 (Vulkan) still RTX 4080 flying
vanilla 1.29 ms 0.95 ms 0.30 ms 0.14 ms
Daybreak (Horizon v1 pack) 2.72 ms 3.87 ms 0.48 ms 0.87 ms
BSL 10.1.8 (Java pack path, full-screen passes only) 3.03 ms 2.70 ms 0.59 ms 0.57 ms
api 1 sample pack (horizon-sample) 1.33 ms

Breakdown on the M4 Pro before the shadow cache: shadow pass at 112 blocks ~0.9 ms; Daybreak's lighting math ~0.4 ms; its five full-screen stages ~0.25 ms; the rest (~1 ms) is the split world pass and the G-buffer (LATER: profile with a Metal capture). The Mac mini was shared with other agents' work (load 40-50), so the M4 numbers are back-to-back comparisons, not absolute.

Windows / DirectX 12

By reasoning plus naga's HLSL backend: every shipped shader (prelude, common, world, terrain and entity hook compositions, and every example pack stage, Rust ones included) is translated to HLSL, MSL and SPIR-V with the pack's constants applied, per entry point (translates_everywhere). Nothing in the passes is backend-specific (no push constants, no storage textures; one read-only storage buffer for materials in the world group).

Checks

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: 1000 passed (15 ignored as on main).
  • Parity, render harnesses this change can reach (tools/parity.py --changed-files; --changed origin/main selects all 327 because Cargo.lock changes): 10 passed, 0 failed: block_entity_render, cloud_render, environment_render, light, options, screen_layout, translucency, weather_render, world_border_render, world_options. The other 92 the source files reach (non-render: they build horizon-client probes) were not run.
  • Ran in the game on Metal (M4 Pro, offscreen) and Vulkan (RTX 4080, headless sway): the panic found on the first run (the shadow pass bound its own map) is fixed here.

Licences of the well-known packs are in the docs table; nothing from any pack is in this PR.

🤖 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/1261 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/horizon-shaders-v1` --- ### 📝 Commits (1) - [`7b06970`](https://github.com/horizon-rust/horizon/commit/7b069708c4e647c0e451a62535f49266216983a3) Horizon shaders v1: shadow maps, world hooks, G-buffer, deferred stages ### 📊 Changes **18 files changed** (+3320 additions, -298 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+1 -0) 📝 `crates/horizon-client/Cargo.toml` (+2 -2) 📝 `crates/horizon-client/src/entity.wgsl` (+4 -0) 📝 `crates/horizon-client/src/game/shader_packs.rs` (+13 -2) 📝 `crates/horizon-client/src/gfx.rs` (+456 -56) 📝 `crates/horizon-client/src/gfx/cull.rs` (+68 -37) 📝 `crates/horizon-client/src/gfx/flat.rs` (+4 -0) 📝 `crates/horizon-client/src/gfx/pack_stages.rs` (+498 -143) ➕ `crates/horizon-client/src/gfx/pack_world.rs` (+738 -0) 📝 `crates/horizon-client/src/gfx/world_post.rs` (+18 -7) 📝 `crates/horizon-client/src/shader_pack.rs` (+890 -19) ➕ `crates/horizon-client/src/shader_pack_common.wgsl` (+101 -0) ➕ `crates/horizon-client/src/shader_pack_entity.wgsl` (+73 -0) 📝 `crates/horizon-client/src/shader_pack_prelude.wgsl` (+43 -27) ➕ `crates/horizon-client/src/shader_pack_terrain.wgsl` (+129 -0) ➕ `crates/horizon-client/src/shader_pack_world.wgsl` (+69 -0) 📝 `crates/horizon-client/src/terrain.wgsl` (+5 -1) 📝 `docs/shader-packs.md` (+208 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. First of the "Horizon shaders v1" PRs (brief shaders-1). This one is the runtime; the stacked PR on top (#1262) adds the Rust SDK, `cargo horizon-shader` and the Daybreak example pack. The options page is a separate, independent PR (#1260). ## Decision: Rust (rust-gpu) for stages, WGSL for world hooks - Full-screen stages can be written in **Rust** with rust-gpu. A pack ships the compiled `.spv`; the game reads it with naga (`spv-in`), validates it and writes it back as WGSL, so wgpu treats it like any stage and it reaches **Metal, Vulkan and DirectX 12** the same way. Players need no toolchain. Checked: Daybreak's five Rust stages translate to MSL, HLSL and SPIR-V in tests, and render the same on Metal (M4 Pro) and Vulkan (RTX 4080). - **World hooks stay WGSL** in v1: rust-gpu emits entry points, while a hook is a function Horizon composes into its own terrain/entity/sky shaders. Rust hooks need a pass lifting functions out of the compiled module through naga IR (FEATURES.md LATER). - Costs, written in the docs: option names don't survive rust-gpu (specialization constants are numbered), so options a Rust stage reads carry an `id`; SPIR-V can't hold images or samplers in structs, so the SDK passes resources one by one. The first `cargo gpu` build installs its pinned nightly (about 12 min on the M4 Pro), later builds take 2-4 s. ## What api 2 adds (docs/shader-packs.md, "Horizon shaders v1") - `[shadow]`: a shadow map from the sun (the moon at night), sections within `distance` culled with the light's frustum, the box moving in whole texels (depth too), distortion towards the player, 4-tap PCF via `shadow_lit()`. **The shadow pass is skipped while its map is still right** (same light step of about 0.015°, same texel box, same casters, no terrain upload since), so a still player redraws it a few times a second instead of every frame. - `[gbuffer]`: WGSL hooks `surface_vertex`, `surface_normal`, `surface_color`, `sky_color`, composed into Horizon's terrain, entity and sky shaders, with defaults for any a pack leaves out. Opaque and translucent surfaces write colour plus an `Rgba16Uint` G-buffer (octahedral normal, block/sky light, material). Flags for vanilla's sun/moon, stars and clouds. - `deferred` stages between opaque and translucent geometry; the opaque depth for stages; `[[target]]` (6 formats, scale, `history` for last frame), `[[texture]]` PNGs, `[materials]` ids 16-255 by sprite glob on top of Horizon's 9 (terrain, leaves, plants, water, lava, glass, emissive, entity). - `Frame` grows (previous view-projection, shadow matrix, camera delta, shadow settings, light direction, world size); the api 1 layout is unchanged in front. - **No pack: no change.** None of the new passes, targets or pipelines exist without a pack; an api 1 pack draws as before (the world pass is split only when a pack has `[gbuffer]`). ## Frame times (1280x720, same scene: seed 42, (-30,100,0) yaw 270 pitch 25, noon, spectator) `bench 20` with the frame limit off, two runs each, p50 frame time, `--profile fast` builds of this branch. "Flying" is `fly` over 80 blocks in 20 s with the daylight cycle on (chunks load, the sun moves, the shadow map redraws). | | M4 Pro (Metal) still | M4 Pro flying | RTX 4080 (Vulkan) still | RTX 4080 flying | | --- | --- | --- | --- | --- | | vanilla | 1.29 ms | 0.95 ms | 0.30 ms | 0.14 ms | | Daybreak (Horizon v1 pack) | 2.72 ms | 3.87 ms | 0.48 ms | 0.87 ms | | BSL 10.1.8 (Java pack path, full-screen passes only) | 3.03 ms | 2.70 ms | 0.59 ms | 0.57 ms | | api 1 sample pack (`horizon-sample`) | 1.33 ms | | | | Breakdown on the M4 Pro before the shadow cache: shadow pass at 112 blocks ~0.9 ms; Daybreak's lighting math ~0.4 ms; its five full-screen stages ~0.25 ms; the rest (~1 ms) is the split world pass and the G-buffer (LATER: profile with a Metal capture). The Mac mini was shared with other agents' work (load 40-50), so the M4 numbers are back-to-back comparisons, not absolute. ## Windows / DirectX 12 By reasoning plus naga's HLSL backend: every shipped shader (prelude, common, world, terrain and entity hook compositions, and every example pack stage, Rust ones included) is translated to HLSL, MSL and SPIR-V with the pack's constants applied, per entry point (`translates_everywhere`). Nothing in the passes is backend-specific (no push constants, no storage textures; one read-only storage buffer for materials in the world group). ## Checks - `cargo fmt --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: 1000 passed (15 ignored as on main). - Parity, render harnesses this change can reach (`tools/parity.py --changed-files`; `--changed origin/main` selects all 327 because Cargo.lock changes): 10 passed, 0 failed: block_entity_render, cloud_render, environment_render, light, options, screen_layout, translucency, weather_render, world_border_render, world_options. The other 92 the source files reach (non-render: they build `horizon-client` probes) were not run. - Ran in the game on Metal (M4 Pro, offscreen) and Vulkan (RTX 4080, headless sway): the panic found on the first run (the shadow pass bound its own map) is fixed here. Licences of the well-known packs are in the docs table; nothing from any pack is in this PR. 🤖 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:09:43 +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#3464
No description provided.