[PR #1326] [MERGED] Java shader packs: the pack's shadow programs draw the shadow map #3487

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

📋 Pull Request Information

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

Base: main ← Head: feat/java-shadow-programs


📝 Commits (10+)

  • 60fc787 Java shader packs: Photon, Chocapic13' and MakeUp Ultra Fast load
  • 91d89b4 Java shader packs: modf into a vector component works in an initialiser
  • 6a58fc2 Java shader packs: the pack's gbuffers_terrain and gbuffers_water draw the terrain
  • c344a26 Java shader packs: occlusion culling while the pack draws the terrain
  • fe6ae93 Java shader packs: the pack's shadow programs draw the shadow map
  • 5858cb1 Java shader packs: the shadow map leaves out sections whose shadow can't reach the view
  • f642105 Merge remote-tracking branch 'origin/main' into feat/java-packs-photon-chocapic
  • ab2bc22 Merge origin/main into feat/java-packs-photon-chocapic
  • 0f3a92a Merge feat/java-packs-photon-chocapic into feat/java-gbuffers-terrain
  • a8c21c2 Merge feat/java-gbuffers-terrain into feat/java-terrain-cull

📊 Changes

17 files changed (+3829 additions, -300 deletions)

View changed files

📝 crates/horizon-client/Cargo.toml (+4 -0)
📝 crates/horizon-client/src/game/shader_packs.rs (+5 -2)
📝 crates/horizon-client/src/gfx.rs (+447 -19)
📝 crates/horizon-client/src/gfx/animate.rs (+6 -0)
📝 crates/horizon-client/src/gfx/arena.rs (+8 -1)
📝 crates/horizon-client/src/gfx/cull.rs (+122 -44)
📝 crates/horizon-client/src/gfx/cull.wgsl (+22 -0)
📝 crates/horizon-client/src/gfx/flat.rs (+14 -2)
📝 crates/horizon-client/src/gfx/java_stages.rs (+1346 -165)
➕ crates/horizon-client/src/gfx/java_terrain.rs (+667 -0)
📝 crates/horizon-client/src/java_pack.rs (+200 -5)
📝 crates/horizon-shaderpack/src/lib.rs (+16 -0)
📝 crates/horizon-shaderpack/src/pipeline.rs (+243 -1)
📝 crates/horizon-shaderpack/src/properties.rs (+112 -2)
📝 crates/horizon-shaderpack/src/translate.rs (+378 -39)
📝 crates/horizon-shaderpack/tests/translate.rs (+162 -1)
📝 docs/shader-packs.md (+77 -19)

📄 Description

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

Stacked on #1290 (feat/java-terrain-cull), which is stacked on #1277 and #1267. This diff is only the shadow piece.

What

A Java pack's shadow programs now draw a shadow map from Horizon's terrain, as Iris's ShadowRenderer does. The passes then read it through shadowtex0/1 and shadowcolor*.

Programs.

  • Solid layer: shadow_cutout, else shadow, else shadow_solid. Horizon's solid layer also holds cutout blocks, so the cutout program comes first.
  • Translucent layer: shadow_water, else shadow.
  • They are translated like the terrain programs, with only the instanced glue. Iris's alpha test of 0.1 applies to the solid layer.
  • They don't blend (BlendModeOverride.OFF) and cull no faces.

When it runs. After begin*, before prepare*, every frame.

Matrices. These are Iris's ShadowMatrices, checked against the expected values in Iris's own tests:

  • shadowModelView: Rx(90) · Rz(−360·skyAngle) · Rx(sunPathRotation), snapped to shadowIntervalSize from the camera position.
  • shadowProjection: symmetric orthographic, shadowDistance each way, between shadowNearPlane and shadowFarPlane. Iris's defaults are 1024 px, 160, −100.05 / 156 and 2.0.
  • Shadow programs get them as gl_ModelViewMatrix/modelViewMatrix and gl_ProjectionMatrix/projectionMatrix; every pass gets the shadow* uniforms.

Sections. Renderer builds its own list each frame:

  • every resident section inside the light's box;
  • cave culling off, as Iris turns it off;
  • casters whose shadow can't reach the camera's view are dropped. The box swept away from the light is tested against the frustum planes, a conservative version of Iris's advanced shadow culling.
  • Their origins go after the camera's in the instance buffer, and their draws go to their own indirect buffer: solid, then translucent.

Textures.

  • shadowtex0 holds everything; shadowtex1 is the depth before translucent terrain.
  • Both are bound as Depth32Float for sampler2DShadow, with linear comparison (Iris's hardware filtering).
  • R32Float copies are made only when a pass reads them through a plain sampler2D.
  • shadowcolor0..7 take shadowcolor<N>Format, Clear and ClearColor. Iris's default is RGBA8 cleared to white. A target with Clear set to false is white once, then kept: MakeUp sets this for shadowcolor0 and shadowcolor1.

Fallback. A shadow program that doesn't translate, or that wgpu refuses, is logged as a warning. The pack keeps its terrain programs, and shadowtex reads as far (nothing in shadow). I tested this with a copy of MakeUp whose shadow.fsh was broken: it warns world0/shadow.fsh:13: unexpected { and draws as before, without shadows (screenshot).

Code.

  • horizon-shaderpack: ShadowDirectives, shadow_target_settings, Passes::{shadow, shadow_water, shadow_targets}.
  • gfx/java_stages.rs: FolderShadow, BoundShadow, draw_shadow, shadow_matrices, JavaStages::shadow_view, and Source::{ShadowDepth, ShadowColor, Far}.
  • gfx.rs: ShadowList, draw_list (generic over a draw list), Frustum::casts_into, and Layer::{ShadowSolid, ShadowTranslucent}.

Proof

Screenshots are on the screenshots/shaders-1 branch, folder java-shadow/. They show seed 42, (-30,100,0), yaw 270, pitch 25. Columns are times 1000 / 6000 / 12400 / 18000 plus the water view.

grid

The grid's rows, from the top:

Row What
1 vanilla
2 MakeUp Ultra Fast 9.6, before
3 MakeUp Ultra Fast 9.6, with shadows
4 Chocapic13' V9 High, before
5 Chocapic13' V9 High, with shadows
6 BSL v10.1.8, before
7 BSL v10.1.8, with shadows
  • Trees now shade the ground, the beach and the mushrooms, and at sunrise and sunset the shadows lengthen with the light.
  • Photon is still black (compute and .dat textures, the next pieces). Its shadow_cutout/shadow_water translate and run.
  • Caster culling doesn't change the picture: BSL with and without it looks the same in all three views, apart from the pack's own frame-to-frame noise.
  • No Iris reference yet: that needs a GUI session.

Frame time (1280x720, noon, still, 20 s, p50). Each line was run twice in alternating order: vanilla, the previous step (#1290's binary) and this one.

M4 Pro (Metal) RTX 4080 (Vulkan)
vanilla 1.29 ms 0.15 ms
MakeUp, #1290 4.40–4.44 ms 0.70 ms
MakeUp, shadows 4.93–4.98 ms (+0.55) 0.85 ms (+0.15)
Chocapic13', #1290 4.40–4.46 ms 0.86 ms
Chocapic13', shadows 5.62–5.74 ms (+1.2) 1.16 ms (+0.30)
BSL, #1290 4.64–4.75 ms 0.86 ms
BSL, shadows 7.63–7.64 ms (+3.0) 1.59 ms (+0.73)
  • On the RTX 4080 these are the second runs; in the first, some launches failed because the previous game hadn't quit yet.

  • Shadow map size and distance by pack:

    Pack Resolution Distance
    MakeUp 1020 px 105
    Chocapic13' 2048 px 128
    BSL 2048 px 256

    BSL's 256 means a 512-block box, so its shadow map draws by far the most terrain.

  • Caster culling alone took BSL from 9.8–10.1 ms to 7.3–7.7 ms on the M4 Pro, measured back to back.

  • On Apple GPUs the shadow list is drawn per section (wgpu emulates multi-draw there), so part of the cost is CPU: p50 CPU time goes from 1.3 to 1.9 ms with BSL. The camera's view uses flat draws to avoid that, and doing the same for the shadow list is the next optimisation.

Tests

  • cargo test -p horizon-shaderpack passes, with shadow_directives_and_targets.
  • cargo test -p horizon-client passes, with:
    • shadow_matrices_are_iris_s: the projection against Iris's expected values, noon looking straight down, the interval snap;
    • shadow_casters_are_the_boxes_whose_shadow_can_reach_the_view;
    • the updated sampler sources.
  • real_packs_load with HORIZON_TEST_SHADERPACKS: MakeUp, Chocapic13', BSL and Photon load their shadow programs, and every one parses again as WGSL.
  • cargo clippy --all-targets and cargo fmt are clean.
  • docs/shader-packs.md: status rows, how the shadow map works, the limits.

Not yet

  • Entities and block entities don't cast shadows.
  • shadowcomp passes don't run.
  • shadowMapFov (a perspective shadow map) isn't supported.
  • shadow.culling and shadowDistanceRenderMul are ignored: the light's box is the only bound.
  • Shadow-depth mipmaps (generateShadowMipmap) aren't made.
  • The shadow list isn't drawn flat on Apple GPUs yet.
  • These are in FEATURES 4y.

🤖 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/1326 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/java-shadow-programs` --- ### 📝 Commits (10+) - [`60fc787`](https://github.com/horizon-rust/horizon/commit/60fc787288ab5d5ebf89cacb61b72b3c4151094b) Java shader packs: Photon, Chocapic13' and MakeUp Ultra Fast load - [`91d89b4`](https://github.com/horizon-rust/horizon/commit/91d89b4abfdac7a1664854aa008efdc9c19e2c3a) Java shader packs: modf into a vector component works in an initialiser - [`6a58fc2`](https://github.com/horizon-rust/horizon/commit/6a58fc20dadaeed3e0e0af151c5b8ad59ca84c60) Java shader packs: the pack's gbuffers_terrain and gbuffers_water draw the terrain - [`c344a26`](https://github.com/horizon-rust/horizon/commit/c344a26e80c4b85c39775d54e7727d7babdae9d5) Java shader packs: occlusion culling while the pack draws the terrain - [`fe6ae93`](https://github.com/horizon-rust/horizon/commit/fe6ae937effdd9a7e5ef89c33c3fea9504f24cae) Java shader packs: the pack's shadow programs draw the shadow map - [`5858cb1`](https://github.com/horizon-rust/horizon/commit/5858cb113e56af1cbc53e1a386b42b1d9c9c82aa) Java shader packs: the shadow map leaves out sections whose shadow can't reach the view - [`f642105`](https://github.com/horizon-rust/horizon/commit/f642105e84f57e79d818ea9b4ef5024be0a74e6f) Merge remote-tracking branch 'origin/main' into feat/java-packs-photon-chocapic - [`ab2bc22`](https://github.com/horizon-rust/horizon/commit/ab2bc22515719ca5ad0d3e1061abec2fcfb3c495) Merge origin/main into feat/java-packs-photon-chocapic - [`0f3a92a`](https://github.com/horizon-rust/horizon/commit/0f3a92ac2bae7ba304c3e7e7ca39b0f1bf6ef5e5) Merge feat/java-packs-photon-chocapic into feat/java-gbuffers-terrain - [`a8c21c2`](https://github.com/horizon-rust/horizon/commit/a8c21c27df9bbf4dacda17da084cb4dfe62467d1) Merge feat/java-gbuffers-terrain into feat/java-terrain-cull ### 📊 Changes **17 files changed** (+3829 additions, -300 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/Cargo.toml` (+4 -0) 📝 `crates/horizon-client/src/game/shader_packs.rs` (+5 -2) 📝 `crates/horizon-client/src/gfx.rs` (+447 -19) 📝 `crates/horizon-client/src/gfx/animate.rs` (+6 -0) 📝 `crates/horizon-client/src/gfx/arena.rs` (+8 -1) 📝 `crates/horizon-client/src/gfx/cull.rs` (+122 -44) 📝 `crates/horizon-client/src/gfx/cull.wgsl` (+22 -0) 📝 `crates/horizon-client/src/gfx/flat.rs` (+14 -2) 📝 `crates/horizon-client/src/gfx/java_stages.rs` (+1346 -165) ➕ `crates/horizon-client/src/gfx/java_terrain.rs` (+667 -0) 📝 `crates/horizon-client/src/java_pack.rs` (+200 -5) 📝 `crates/horizon-shaderpack/src/lib.rs` (+16 -0) 📝 `crates/horizon-shaderpack/src/pipeline.rs` (+243 -1) 📝 `crates/horizon-shaderpack/src/properties.rs` (+112 -2) 📝 `crates/horizon-shaderpack/src/translate.rs` (+378 -39) 📝 `crates/horizon-shaderpack/tests/translate.rs` (+162 -1) 📝 `docs/shader-packs.md` (+77 -19) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1290 (`feat/java-terrain-cull`), which is stacked on #1277 and #1267. This diff is only the shadow piece. ## What A Java pack's `shadow` programs now draw a shadow map from Horizon's terrain, as Iris's `ShadowRenderer` does. The passes then read it through `shadowtex0/1` and `shadowcolor*`. **Programs.** - Solid layer: `shadow_cutout`, else `shadow`, else `shadow_solid`. Horizon's solid layer also holds cutout blocks, so the cutout program comes first. - Translucent layer: `shadow_water`, else `shadow`. - They are translated like the terrain programs, with only the instanced glue. Iris's alpha test of 0.1 applies to the solid layer. - They don't blend (`BlendModeOverride.OFF`) and cull no faces. **When it runs.** After `begin*`, before `prepare*`, every frame. **Matrices.** These are Iris's `ShadowMatrices`, checked against the expected values in Iris's own tests: - `shadowModelView`: Rx(90) · Rz(−360·skyAngle) · Rx(`sunPathRotation`), snapped to `shadowIntervalSize` from the camera position. - `shadowProjection`: symmetric orthographic, `shadowDistance` each way, between `shadowNearPlane` and `shadowFarPlane`. Iris's defaults are 1024 px, 160, −100.05 / 156 and 2.0. - Shadow programs get them as `gl_ModelViewMatrix`/`modelViewMatrix` and `gl_ProjectionMatrix`/`projectionMatrix`; every pass gets the `shadow*` uniforms. **Sections.** `Renderer` builds its own list each frame: - every resident section inside the light's box; - cave culling off, as Iris turns it off; - casters whose shadow can't reach the camera's view are dropped. The box swept away from the light is tested against the frustum planes, a conservative version of Iris's advanced shadow culling. - Their origins go after the camera's in the instance buffer, and their draws go to their own indirect buffer: solid, then translucent. **Textures.** - `shadowtex0` holds everything; `shadowtex1` is the depth before translucent terrain. - Both are bound as `Depth32Float` for `sampler2DShadow`, with linear comparison (Iris's hardware filtering). - `R32Float` copies are made only when a pass reads them through a plain `sampler2D`. - `shadowcolor0..7` take `shadowcolor<N>Format`, `Clear` and `ClearColor`. Iris's default is RGBA8 cleared to white. A target with `Clear` set to false is white once, then kept: MakeUp sets this for `shadowcolor0` and `shadowcolor1`. **Fallback.** A shadow program that doesn't translate, or that wgpu refuses, is logged as a warning. The pack keeps its terrain programs, and `shadowtex` reads as far (nothing in shadow). I tested this with a copy of MakeUp whose `shadow.fsh` was broken: it warns `world0/shadow.fsh:13: unexpected {` and draws as before, without shadows ([screenshot](https://github.com/ludovic111/horizon/blob/screenshots/shaders-1/java-shadow/makeup_broken_shadow_fallback.jpg)). **Code.** - `horizon-shaderpack`: `ShadowDirectives`, `shadow_target_settings`, `Passes::{shadow, shadow_water, shadow_targets}`. - `gfx/java_stages.rs`: `FolderShadow`, `BoundShadow`, `draw_shadow`, `shadow_matrices`, `JavaStages::shadow_view`, and `Source::{ShadowDepth, ShadowColor, Far}`. - `gfx.rs`: `ShadowList`, `draw_list` (generic over a draw list), `Frustum::casts_into`, and `Layer::{ShadowSolid, ShadowTranslucent}`. ## Proof **Screenshots** are on the `screenshots/shaders-1` branch, folder [`java-shadow/`](https://github.com/ludovic111/horizon/tree/screenshots/shaders-1/java-shadow). They show seed 42, (-30,100,0), yaw 270, pitch 25. Columns are times 1000 / 6000 / 12400 / 18000 plus the water view. ![grid](https://raw.githubusercontent.com/ludovic111/horizon/screenshots/shaders-1/java-shadow/grid_shadow.jpg) The grid's rows, from the top: | Row | What | | --- | --- | | 1 | vanilla | | 2 | MakeUp Ultra Fast 9.6, before | | 3 | MakeUp Ultra Fast 9.6, with shadows | | 4 | Chocapic13' V9 High, before | | 5 | Chocapic13' V9 High, with shadows | | 6 | BSL v10.1.8, before | | 7 | BSL v10.1.8, with shadows | - Trees now shade the ground, the beach and the mushrooms, and at sunrise and sunset the shadows lengthen with the light. - Photon is still black (compute and `.dat` textures, the next pieces). Its `shadow_cutout`/`shadow_water` translate and run. - Caster culling doesn't change the picture: BSL with and without it looks the same in all three views, apart from the pack's own frame-to-frame noise. - No Iris reference yet: that needs a GUI session. **Frame time** (1280x720, noon, still, 20 s, p50). Each line was run twice in alternating order: vanilla, the previous step (#1290's binary) and this one. | | M4 Pro (Metal) | RTX 4080 (Vulkan) | | --- | --- | --- | | vanilla | 1.29 ms | 0.15 ms | | MakeUp, #1290 | 4.40–4.44 ms | 0.70 ms | | MakeUp, shadows | 4.93–4.98 ms (+0.55) | 0.85 ms (+0.15) | | Chocapic13', #1290 | 4.40–4.46 ms | 0.86 ms | | Chocapic13', shadows | 5.62–5.74 ms (+1.2) | 1.16 ms (+0.30) | | BSL, #1290 | 4.64–4.75 ms | 0.86 ms | | BSL, shadows | 7.63–7.64 ms (+3.0) | 1.59 ms (+0.73) | - On the RTX 4080 these are the second runs; in the first, some launches failed because the previous game hadn't quit yet. - Shadow map size and distance by pack: | Pack | Resolution | Distance | | --- | --- | --- | | MakeUp | 1020 px | 105 | | Chocapic13' | 2048 px | 128 | | BSL | 2048 px | 256 | BSL's 256 means a 512-block box, so its shadow map draws by far the most terrain. - Caster culling alone took BSL from 9.8–10.1 ms to 7.3–7.7 ms on the M4 Pro, measured back to back. - On Apple GPUs the shadow list is drawn per section (wgpu emulates multi-draw there), so part of the cost is CPU: p50 CPU time goes from 1.3 to 1.9 ms with BSL. The camera's view uses flat draws to avoid that, and doing the same for the shadow list is the next optimisation. ## Tests - `cargo test -p horizon-shaderpack` passes, with `shadow_directives_and_targets`. - `cargo test -p horizon-client` passes, with: - `shadow_matrices_are_iris_s`: the projection against Iris's expected values, noon looking straight down, the interval snap; - `shadow_casters_are_the_boxes_whose_shadow_can_reach_the_view`; - the updated sampler sources. - `real_packs_load` with `HORIZON_TEST_SHADERPACKS`: MakeUp, Chocapic13', BSL and Photon load their shadow programs, and every one parses again as WGSL. - `cargo clippy --all-targets` and `cargo fmt` are clean. - `docs/shader-packs.md`: status rows, how the shadow map works, the limits. ## Not yet - Entities and block entities don't cast shadows. - `shadowcomp` passes don't run. - `shadowMapFov` (a perspective shadow map) isn't supported. - `shadow.culling` and `shadowDistanceRenderMul` are ignored: the light's box is the only bound. - Shadow-depth mipmaps (`generateShadowMipmap`) aren't made. - The shadow list isn't drawn flat on Apple GPUs yet. - These are in FEATURES 4y. 🤖 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:53 +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#3487
No description provided.