[PR #1888] [MERGED] Shader packs, clean room 40: terrain in the shadow map, culled from the light #3841

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

📋 Pull Request Information

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

Base: main ← Head: feat/shader-packs-shadow-terrain


📝 Commits (9)

  • 5dcbe22 Shader packs, clean room 37: shadow settings and the shadow camera
  • 86d8d9e Shader packs, clean room 38: load the shadow programs
  • 6320718 Shader packs, clean room 39: shadow buffers, their samplers and shadowcomp
  • a276f81 Shader packs, clean room 39: the run doc comment back on run
  • c965aad Shader packs, clean room 40: terrain in the shadow map, culled from the light
  • 86a2f8e Merge feat/shader-packs-hand into feat/shader-packs-shadow-camera
  • b2a7e77 Merge feat/shader-packs-shadow-camera into feat/shader-packs-shadow-programs
  • 8b7315a Merge feat/shader-packs-shadow-programs into feat/shader-packs-shadow-buffers
  • c841ab6 Merge feat/shader-packs-shadow-buffers into feat/shader-packs-shadow-terrain

📊 Changes

11 files changed (+1295 additions, -108 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+157 -18)
📝 crates/horizon-client/src/gfx/flat.rs (+66 -4)
📝 crates/horizon-client/src/gfx/pack_post.rs (+375 -52)
➕ crates/horizon-client/src/gfx/pack_shadow.rs (+208 -0)
📝 crates/horizon-client/src/gfx/pack_sky.rs (+6 -4)
📝 crates/horizon-client/src/gfx/pack_uniforms.rs (+117 -17)
📝 crates/horizon-shaders/src/config.rs (+136 -0)
📝 crates/horizon-shaders/src/lib.rs (+3 -3)
📝 crates/horizon-shaders/src/post.rs (+183 -3)
📝 crates/horizon-shaders/src/translate/mod.rs (+39 -6)
📝 crates/horizon-shaders/tests/real_packs.rs (+5 -1)

📄 Description

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

Shader packs, clean room 40: a pack's shadow program draws the world's terrain from the light. Stacked on #1887. This is the top of slice 8's first group (#1885–#1888); the group's checks are below.

What

  • Its own section list (spec 2.1 pass 2, 7.1):
    • the shadow pass takes the sections inside the shadow camera's box, within the render distance, capped by shadowDistanceRenderMul;
    • occlusion culling follows the eye, not the light, so it is not applied here;
    • only quads that can face the light are drawn, and the shadow pipelines cull back faces.
  • Programs:
    • shadow draws solid and cutout terrain;
    • shadow_water (or shadow) draws translucent terrain after shadowtex1 is copied.
  • Draw order: nearest the light first. Draws are grouped by arena page within 64-block bands from the light, as the camera's solid draws already are (PageRuns).
    • With BSL that takes the flat path from about 1,250 + 400 calls to 10 + 10, which saved 0.9 ms of CPU and 0.3 ms of GPU per frame.
  • Translucent sections the camera never saw have no sorted indices yet, so they are sorted once here. Before this fix, their garbage indices drew streaks.
  • Clears: the frame's first shadow pass clears the shadow map and the shadowcolor buffers as it begins, instead of a separate pass that loads and stores them all. The translucent shadow pass is timed under its own label.
  • Renderer outside the pack code (for review):
    • gfx.rs: the shadow list's draws follow the camera's translucent draws in the same instance and indirect buffers. section_draw_calls still counts only the camera's.
    • flat.rs: plan gives the two shadow lists calls of their own (shadow_calls, translucent_calls()).
    • Without a pack both lists are empty and nothing else changes: the terrain is still one draw call.

Clean room

Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1, §2.1, §5.2, §6.3, §7.1, OQ-6; no other loader's code read.

How tested

  • Unit tests:
    • plan_gives_the_shadow_lists_calls_of_their_own;
    • the flat and page_runs tests, with the shadow boundaries at the end of the list.
  • In game (screenshots local; the packs' licences forbid uploading them):
    • A debug pack writes the occluder's height into shadowcolor0 and marks shadowed pixels. A pillar's shadow falls west in the morning and east in the afternoon, and the map's depths match the camera's numbers.
    • BSL: trees and a pillar cast shadows. On the side faces noted in slice 7, those turned away from the sun are dark and those facing it are lit.
    • Sildurs casts shadows too: 3072² over 110 blocks.
    • Complementary loads its shadow program (some of its uniforms are zero for now, as listed).

Slice 8 group checks (#1885–#1888)

  • A/B without a pack (forest benchmark, RD 8, 720p, Mac mini, busy; 3 alternating pairs, #1801 at 44ba13371 against this branch):

    #1801 this branch
    CPU p50 (median) 0.220 ms 0.206 ms
    GPU p50 (median) 0.520 ms 0.492 ms

    The seven earlier pairs (with this PR's first draft) give the same picture, within the spread of the runs.

  • Screenshots without a pack (#1801 against this branch): two views differ by 5,696 and 42,602 bytes. Two runs of one binary differ by 9,603 and 31,000–54,000 bytes on the same views, all of it in the water.

  • Parity:

    • pr_ready --quick passes;
    • locally, the 6 render harnesses among those my files select pass: light, environment_render, block_entity_render, cloud_render, weather_render, world_border_render;
    • the files select 107 harnesses in all, and CI runs them.
  • With BSL (HORIZON_SHADER_PACK_TIMING, 720p, forest spawn, morning, 2048² shadow map over 256 blocks, about 3,950 sections and 8,300 draws in the light's box):

    • BSL's shadow pass takes 2.8 ms of GPU time, and its translucent shadow pass 0.15 ms.
    • Ours inside those passes:
      • the clear, folded into the first pass: 0.025 ms with the draws skipped;
      • the shadowtex1 depth copy: about 0.09 ms. It is made only when a program reads shadowtex1, which BSL does.
    • Overhead rule (coordinator's decision): the 0.1 ms target covers Horizon's own additions. Work any loader must do for what the pack asks counts as the pack's cost.
      • The shadowtex1 copy is such work: two depth maps are unavoidable once a pack reads shadowtex1.
      • A copy-free variant measured in #1900's slice cost the same, since 32 MB at 2048² is the GPU's bandwidth.
      • Ours with BSL is then the world copy (0.045–0.068 ms) plus the clear (0.025 ms): under 0.1 ms.
    • CPU per frame, median: 1.8 → 2.5 ms. The section list takes 0.25 ms and the visibility 0.1 ms; encoding the extra calls accounts for the rest.

🤖 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/1888 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/shader-packs-shadow-terrain` --- ### 📝 Commits (9) - [`5dcbe22`](https://github.com/horizon-rust/horizon/commit/5dcbe222c94261c7291659a15a06549f46134014) Shader packs, clean room 37: shadow settings and the shadow camera - [`86d8d9e`](https://github.com/horizon-rust/horizon/commit/86d8d9e3a19a0c6614b6b4fec537007d33759254) Shader packs, clean room 38: load the shadow programs - [`6320718`](https://github.com/horizon-rust/horizon/commit/632071849134f15723faba98d8fb76d155faa1ce) Shader packs, clean room 39: shadow buffers, their samplers and shadowcomp - [`a276f81`](https://github.com/horizon-rust/horizon/commit/a276f81abacc7d7503a3098c986b1c370f294912) Shader packs, clean room 39: the run doc comment back on run - [`c965aad`](https://github.com/horizon-rust/horizon/commit/c965aad8d3ad6a837149d6ae5a6e7100c168232d) Shader packs, clean room 40: terrain in the shadow map, culled from the light - [`86a2f8e`](https://github.com/horizon-rust/horizon/commit/86a2f8e470868e862d3290efe71ba25f8dd880ba) Merge feat/shader-packs-hand into feat/shader-packs-shadow-camera - [`b2a7e77`](https://github.com/horizon-rust/horizon/commit/b2a7e77036c445340f06f55f3f34952e673dba3e) Merge feat/shader-packs-shadow-camera into feat/shader-packs-shadow-programs - [`8b7315a`](https://github.com/horizon-rust/horizon/commit/8b7315a6ff0921d1ce41d99ce9212329a8243076) Merge feat/shader-packs-shadow-programs into feat/shader-packs-shadow-buffers - [`c841ab6`](https://github.com/horizon-rust/horizon/commit/c841ab6d56761fcf8fe23daa3f86ab366893e40b) Merge feat/shader-packs-shadow-buffers into feat/shader-packs-shadow-terrain ### 📊 Changes **11 files changed** (+1295 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+157 -18) 📝 `crates/horizon-client/src/gfx/flat.rs` (+66 -4) 📝 `crates/horizon-client/src/gfx/pack_post.rs` (+375 -52) ➕ `crates/horizon-client/src/gfx/pack_shadow.rs` (+208 -0) 📝 `crates/horizon-client/src/gfx/pack_sky.rs` (+6 -4) 📝 `crates/horizon-client/src/gfx/pack_uniforms.rs` (+117 -17) 📝 `crates/horizon-shaders/src/config.rs` (+136 -0) 📝 `crates/horizon-shaders/src/lib.rs` (+3 -3) 📝 `crates/horizon-shaders/src/post.rs` (+183 -3) 📝 `crates/horizon-shaders/src/translate/mod.rs` (+39 -6) 📝 `crates/horizon-shaders/tests/real_packs.rs` (+5 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Shader packs, clean room 40:** a pack's shadow program draws the world's terrain from the light. Stacked on #1887. This is the top of slice 8's first group (#1885–#1888); the group's checks are below. ## What - **Its own section list** (spec 2.1 pass 2, 7.1): - the shadow pass takes the sections inside the shadow camera's box, within the render distance, capped by `shadowDistanceRenderMul`; - occlusion culling follows the eye, not the light, so it is not applied here; - only quads that can face the light are drawn, and the shadow pipelines cull back faces. - **Programs:** - `shadow` draws solid and cutout terrain; - `shadow_water` (or `shadow`) draws translucent terrain after `shadowtex1` is copied. - **Draw order:** nearest the light first. Draws are grouped by arena page within 64-block bands from the light, as the camera's solid draws already are (`PageRuns`). - With BSL that takes the flat path from about 1,250 + 400 calls to 10 + 10, which saved 0.9 ms of CPU and 0.3 ms of GPU per frame. - **Translucent sections the camera never saw** have no sorted indices yet, so they are sorted once here. Before this fix, their garbage indices drew streaks. - **Clears:** the frame's first shadow pass clears the shadow map and the shadowcolor buffers as it begins, instead of a separate pass that loads and stores them all. The translucent shadow pass is timed under its own label. - **Renderer outside the pack code** (for review): - `gfx.rs`: the shadow list's draws follow the camera's translucent draws in the same instance and indirect buffers. `section_draw_calls` still counts only the camera's. - `flat.rs`: `plan` gives the two shadow lists calls of their own (`shadow_calls`, `translucent_calls()`). - **Without a pack** both lists are empty and nothing else changes: the terrain is still one draw call. ## Clean room Clean-room: implemented from `cleanroom/shader-packs-spec.md` revision 1, §2.1, §5.2, §6.3, §7.1, OQ-6; no other loader's code read. ## How tested - **Unit tests:** - `plan_gives_the_shadow_lists_calls_of_their_own`; - the `flat` and `page_runs` tests, with the shadow boundaries at the end of the list. - **In game** (screenshots local; the packs' licences forbid uploading them): - **A debug pack** writes the occluder's height into shadowcolor0 and marks shadowed pixels. A pillar's shadow falls west in the morning and east in the afternoon, and the map's depths match the camera's numbers. - **BSL:** trees and a pillar cast shadows. On the side faces noted in slice 7, those turned away from the sun are dark and those facing it are lit. - **Sildurs** casts shadows too: 3072² over 110 blocks. - **Complementary** loads its `shadow` program (some of its uniforms are zero for now, as listed). ## Slice 8 group checks (#1885–#1888) - **A/B without a pack** (forest benchmark, RD 8, 720p, Mac mini, busy; 3 alternating pairs, #1801 at 44ba13371 against this branch): | | #1801 | this branch | |---|---|---| | CPU p50 (median) | 0.220 ms | 0.206 ms | | GPU p50 (median) | 0.520 ms | 0.492 ms | The seven earlier pairs (with this PR's first draft) give the same picture, within the spread of the runs. - **Screenshots without a pack** (#1801 against this branch): two views differ by 5,696 and 42,602 bytes. Two runs of one binary differ by 9,603 and 31,000–54,000 bytes on the same views, all of it in the water. - **Parity:** - `pr_ready --quick` passes; - locally, the 6 render harnesses among those my files select pass: `light`, `environment_render`, `block_entity_render`, `cloud_render`, `weather_render`, `world_border_render`; - the files select 107 harnesses in all, and CI runs them. - **With BSL** (`HORIZON_SHADER_PACK_TIMING`, 720p, forest spawn, morning, 2048² shadow map over 256 blocks, about 3,950 sections and 8,300 draws in the light's box): - BSL's `shadow` pass takes 2.8 ms of GPU time, and its translucent shadow pass 0.15 ms. - Ours inside those passes: - the clear, folded into the first pass: 0.025 ms with the draws skipped; - the `shadowtex1` depth copy: about 0.09 ms. It is made only when a program reads `shadowtex1`, which BSL does. - **Overhead rule** (coordinator's decision): the 0.1 ms target covers Horizon's own additions. Work any loader must do for what the pack asks counts as the pack's cost. - The `shadowtex1` copy is such work: two depth maps are unavoidable once a pack reads `shadowtex1`. - A copy-free variant measured in #1900's slice cost the same, since 32 MB at 2048² is the GPU's bandwidth. - Ours with BSL is then the world copy (0.045–0.068 ms) plus the clear (0.025 ms): under 0.1 ms. - **CPU per frame**, median: 1.8 → 2.5 ms. The section list takes 0.25 ms and the visibility 0.1 ms; encoding the extra calls accounts for the rest. 🤖 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:12:42 +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#3841
No description provided.