[PR #5461] [MERGED] Shader API: [shadow], a shadow map of the solid terrain #6301

Closed
opened 2026-11-03 06:17:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: shader/s6-shadow-solid


📝 Commits (6)

  • acc8c21 Shader API: [shadow], a shadow map of the solid terrain
  • 8859015 Merge main into #5461
  • b13a22f Merge remote-tracking branch 'origin/main' into shader/s6-shadow-solid
  • d5316ca Shader API: review fixes for [shadow]
  • e554c66 Merge main into #5461
  • 205d4c3 Merge main into #5461 (after the native shader params, #5411)

📊 Changes

17 files changed (+729 additions, -19 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+43 -1)
📝 crates/horizon-client-render/src/gfx/native_pack.rs (+14 -1)
📝 crates/horizon-client-render/src/gfx/native_post.rs (+96 -5)
➕ crates/horizon-client-render/src/gfx/native_shadow.rs (+377 -0)
📝 crates/horizon-client-render/src/gfx/native_sky.rs (+1 -1)
📝 crates/horizon-client-render/src/gfx/pack_uniforms.rs (+7 -2)
📝 crates/horizon-shader-api/src/check.rs (+3 -0)
📝 crates/horizon-shader-api/src/inputs.rs (+22 -2)
📝 crates/horizon-shader-api/src/manifest.rs (+47 -0)
📝 crates/horizon-shader-api/src/reference.rs (+9 -1)
📝 crates/horizon-shader-api/src/stages.rs (+51 -4)
📝 crates/horizon-shader-api/tests/samples/schema-1/horizon-shaders.toml (+4 -0)
📝 crates/horizon-shader-api/tests/schema.rs (+20 -0)
📝 crates/horizon-shaders/src/config.rs (+4 -0)
📝 docs/api/shaders-reference.md (+20 -0)
📝 docs/api/shaders.md (+10 -1)
📝 docs/shaders.md (+1 -1)

📄 Description

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

What

Adds [shadow] to the native shader API. It's the next slice of the stack that merged through #4398.

  • Manifest: [shadow] with resolution (256 to 8192, default 2048) and distance (32 to 512 blocks, default 128). It needs [material] or [[post]].
  • Stages: the material stage reads shadow_map and shadow_sampler at bindings 3 and 4, the post stage at 6 and 7. Both preludes get shadow_position.
  • Frame: light_direction, has_shadow, shadow_view_proj, shadow_distance, shadow_distortion, shadow_resolution and shadow_center_texel, appended after the existing fields (size 624).
  • Renderer: native_shadow.rs draws solid terrain, instanced or flat, from the shadow lists shaders/ packs already use. A pack without [shadow] gets a 1x1 map that lights everything, and no shadow pass runs.

Not in this PR:

  • Translucent terrain and entities don't cast yet.
  • The pass has no GPU timing entry in the overlay.

Size: this is over the ~500 line guide. The manifest, the stage inputs and the pass only do something together, so I didn't split them further.

Layout decision: shadow_resolution and shadow_center_texel also pad Frame to a multiple of 16 without an unnamed field. Say if you'd rather have a plain padding field.

Fixes #5460

Proof

Run locally on Windows, on this branch, with a throwaway pack that darkens terrain by the map and tints shaded pixels red in the right third of the post stage:

  • Single player, server thread (horizon-ctl launch --world Test): the pack loaded with no shader error. Two pillars on a stone floor cast shadows that shorten from time set 1500 to 4000 to 6000 and move with the sun, and they fall on water too.
  • Post stage: it reads the same map, but that was only seen on a small part of the frame in this scene, so it's weaker evidence than the material stage.
  • Self-shadowing: with the test pack's small constant bias, vertical faces show stripes at noon. A pack sets its own bias, so shadow_center_texel is there to scale it.
  • lan_e2e --check chest: exit 0. I ran only this check, and this PR doesn't change networking.
  • Not run: parity harnesses, and other lan_e2e checks. The in-frame path is deprecated per AGENTS.md. No screenshot is attached: I can't upload one here without committing it, and a capture shows Mojang's textures. A maintainer can repeat this with any pack that reads shadow_map.

A bug found this way is covered by what_the_camera_stands_on_is_inside_the_shadow_cameras_depth: Shadow::near makes the projection's near plane -near, so a negative value gave an empty depth range and NaN positions.

pr_ready (tools/pr_ready.py --quick on Teiwazik, against origin/main at 256a52eb2, 4 min 29 s)

Check Result
Scope ⚠️ 13 files, +667 −14; 637 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 508 passed (1 min 24 s)
rustfmt ✅ (16 s)
clippy ✅ (1 min 22 s)
tests: horizon-client-render, horizon-shader-api ✅ 838 passed (1 min 21 s)
doc tests ✅ 0 passed (2 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.ai/code/session_01EBqm1v5zTsDGwuZF6XKFjL


🔄 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/5461 **Author:** [@Teiwazik](https://github.com/Teiwazik) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `shader/s6-shadow-solid` --- ### 📝 Commits (6) - [`acc8c21`](https://github.com/horizon-rust/horizon/commit/acc8c21f4c9d3f146413b5230d93af9599085c4f) Shader API: [shadow], a shadow map of the solid terrain - [`8859015`](https://github.com/horizon-rust/horizon/commit/88590156f0d68856c06988cb2b3ca97d64c27217) Merge main into #5461 - [`b13a22f`](https://github.com/horizon-rust/horizon/commit/b13a22fdcbac449c92b9140fdfdeacbd71b7a5e2) Merge remote-tracking branch 'origin/main' into shader/s6-shadow-solid - [`d5316ca`](https://github.com/horizon-rust/horizon/commit/d5316caaaf16a8268cdf6032bbb2a6eb6951a621) Shader API: review fixes for [shadow] - [`e554c66`](https://github.com/horizon-rust/horizon/commit/e554c66ae2882460d80a4209893cc0a74eedd71c) Merge main into #5461 - [`205d4c3`](https://github.com/horizon-rust/horizon/commit/205d4c32c7ad584e788271179d74154380d6b31a) Merge main into #5461 (after the native shader params, #5411) ### 📊 Changes **17 files changed** (+729 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+43 -1) 📝 `crates/horizon-client-render/src/gfx/native_pack.rs` (+14 -1) 📝 `crates/horizon-client-render/src/gfx/native_post.rs` (+96 -5) ➕ `crates/horizon-client-render/src/gfx/native_shadow.rs` (+377 -0) 📝 `crates/horizon-client-render/src/gfx/native_sky.rs` (+1 -1) 📝 `crates/horizon-client-render/src/gfx/pack_uniforms.rs` (+7 -2) 📝 `crates/horizon-shader-api/src/check.rs` (+3 -0) 📝 `crates/horizon-shader-api/src/inputs.rs` (+22 -2) 📝 `crates/horizon-shader-api/src/manifest.rs` (+47 -0) 📝 `crates/horizon-shader-api/src/reference.rs` (+9 -1) 📝 `crates/horizon-shader-api/src/stages.rs` (+51 -4) 📝 `crates/horizon-shader-api/tests/samples/schema-1/horizon-shaders.toml` (+4 -0) 📝 `crates/horizon-shader-api/tests/schema.rs` (+20 -0) 📝 `crates/horizon-shaders/src/config.rs` (+4 -0) 📝 `docs/api/shaders-reference.md` (+20 -0) 📝 `docs/api/shaders.md` (+10 -1) 📝 `docs/shaders.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Teiwazik's AI agent (Claude Code, Claude Opus 5.5), not by Teiwazik personally. ## What Adds `[shadow]` to the native shader API. It's the next slice of the stack that merged through #4398. - **Manifest:** `[shadow]` with `resolution` (256 to 8192, default 2048) and `distance` (32 to 512 blocks, default 128). It needs `[material]` or `[[post]]`. - **Stages:** the material stage reads `shadow_map` and `shadow_sampler` at bindings 3 and 4, the post stage at 6 and 7. Both preludes get `shadow_position`. - **`Frame`:** `light_direction`, `has_shadow`, `shadow_view_proj`, `shadow_distance`, `shadow_distortion`, `shadow_resolution` and `shadow_center_texel`, appended after the existing fields (size 624). - **Renderer:** `native_shadow.rs` draws solid terrain, instanced or flat, from the shadow lists `shaders/` packs already use. A pack without `[shadow]` gets a 1x1 map that lights everything, and no shadow pass runs. **Not in this PR:** - Translucent terrain and entities don't cast yet. - The pass has no GPU timing entry in the overlay. **Size:** this is over the ~500 line guide. The manifest, the stage inputs and the pass only do something together, so I didn't split them further. **Layout decision:** `shadow_resolution` and `shadow_center_texel` also pad `Frame` to a multiple of 16 without an unnamed field. Say if you'd rather have a plain padding field. Fixes #5460 ## Proof Run locally on Windows, on this branch, with a throwaway pack that darkens terrain by the map and tints shaded pixels red in the right third of the post stage: - **Single player, server thread** (`horizon-ctl launch --world Test`): the pack loaded with no shader error. Two pillars on a stone floor cast shadows that shorten from `time set 1500` to 4000 to 6000 and move with the sun, and they fall on water too. - **Post stage:** it reads the same map, but that was only seen on a small part of the frame in this scene, so it's weaker evidence than the material stage. - **Self-shadowing:** with the test pack's small constant bias, vertical faces show stripes at noon. A pack sets its own bias, so `shadow_center_texel` is there to scale it. - **`lan_e2e --check chest`:** exit 0. I ran only this check, and this PR doesn't change networking. - **Not run:** parity harnesses, and other `lan_e2e` checks. The in-frame path is deprecated per AGENTS.md. No screenshot is attached: I can't upload one here without committing it, and a capture shows Mojang's textures. A maintainer can repeat this with any pack that reads `shadow_map`. A bug found this way is covered by `what_the_camera_stands_on_is_inside_the_shadow_cameras_depth`: `Shadow::near` makes the projection's near plane `-near`, so a negative value gave an empty depth range and NaN positions. **pr_ready** (`tools/pr_ready.py --quick` on Teiwazik, against origin/main at 256a52eb2, 4 min 29 s) | Check | Result | | --- | --- | | Scope | ⚠️ 13 files, +667 −14; 637 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 508 passed (1 min 24 s) | | rustfmt | ✅ (16 s) | | clippy | ✅ (1 min 22 s) | | tests: horizon-client-render, horizon-shader-api | ✅ 838 passed (1 min 21 s) | | doc tests | ✅ 0 passed (2 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) https://claude.ai/code/session_01EBqm1v5zTsDGwuZF6XKFjL --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:17:58 +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#6301
No description provided.