[PR #1277] [MERGED] Java shader packs: the pack's gbuffers_terrain and gbuffers_water draw the terrain #3475

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

📋 Pull Request Information

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

Base: main ← Head: feat/java-gbuffers-terrain


📝 Commits (3)

  • 6a58fc2 Java shader packs: the pack's gbuffers_terrain and gbuffers_water draw the terrain
  • 0f3a92a Merge feat/java-packs-photon-chocapic into feat/java-gbuffers-terrain
  • c924894 Merge remote-tracking branch 'origin/main' into feat/java-gbuffers-terrain

📊 Changes

15 files changed (+2257 additions, -202 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 (+214 -13)
📝 crates/horizon-client/src/gfx/animate.rs (+6 -0)
📝 crates/horizon-client/src/gfx/arena.rs (+8 -1)
📝 crates/horizon-client/src/gfx/flat.rs (+10 -1)
📝 crates/horizon-client/src/gfx/java_stages.rs (+743 -146)
➕ crates/horizon-client/src/gfx/java_terrain.rs (+645 -0)
📝 crates/horizon-client/src/java_pack.rs (+138 -5)
📝 crates/horizon-shaderpack/src/lib.rs (+16 -0)
📝 crates/horizon-shaderpack/src/pipeline.rs (+109 -1)
📝 crates/horizon-shaderpack/src/properties.rs (+88 -0)
📝 crates/horizon-shaderpack/src/translate.rs (+142 -16)
📝 crates/horizon-shaderpack/tests/translate.rs (+90 -1)
📝 docs/shader-packs.md (+39 -16)

📄 Description

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

Stacked on #1267 (feat/java-packs-photon-chocapic): review that one first; this diff is only the terrain piece.

What

Java shader packs now draw Horizon's terrain with their own gbuffers_terrain and gbuffers_water, as Iris does, instead of only post-processing Horizon's world.

  • Translator, geometry mode (horizon-shaderpack/src/translate.rs): the pack's bindings move to group 2, its vertex attributes become globals that a glue function fills before main, and fragments under alphaTestRef (0.1) are discarded. A new IR pass ends switch cases that return. Without it, naga's WGSL writer rejects Photon's terrain program ("fall-through switch case block").
  • Glue (gfx/java_terrain.rs): the pack's vertex program reads Horizon's own terrain vertices from the arena pages, through both the instanced and the flat draws. The glue decodes them into Iris's attributes:
    • vaPosition/gl_Vertex relative to the camera;
    • colour with vanilla's face shade undone;
    • UV, lightmap 0..240;
    • normal and at_tangent from the quad's four corners;
    • mc_midTexCoord, at_midBlock;
    • mc_Entity.x from the pack's block.properties, matched to each sprite's block by name.
  • Textures: gtexture is a 2D atlas built once from Horizon's sprite arrays; animated sprites are copied in each frame. lightmap is Horizon's lightmap with Iris's texture matrix.
  • Order (gfx/java_stages.rs):
    1. Horizon's world pass skips its own terrain.
    2. At world_at, after the rest of the world enters colortex0 and depth, the terrain program draws into the pack's RENDERTARGETS and the depth goes into depthtex0/depthtex1.
    3. Before the first composite, gbuffers_water draws the translucent layer with the pack's blend.* (or vanilla's) and the depth goes into depthtex0.
  • 16-bit targets: RGBA16/RG16/R16 targets are 16-bit unorm where the adapter can render and filter them (TEXTURE_FORMAT_16BIT_NORM plus adapter-specific format features). Chocapic13' packs its G-buffer into RGBA16, and with half floats its leaves came out red-dotted.
  • Fallback: a pack whose terrain programs fail to compile warns and falls back to the full-screen-only path.
  • Docs: docs/shader-packs.md (status, how it works, limits, compatibility rows).

Proof

Screenshots are on the screenshots/shaders-1 branch, folder java-terrain/. They show seed 42 at (-30,100,0), yaw 270, pitch 25. Columns are times 1000 / 6000 / 12400 / 18000 plus a water view at 6000. Rows are vanilla / MakeUp Ultra Fast 9.6 / Chocapic13' V9 High / BSL v10.1.8 / Photon v1.4:

grid

MakeUp, Chocapic13' and BSL now show their own terrain lighting, water and fog. Photon still draws black: its sky and light come from a compute pass and .dat look-up tables, which is the next piece. No Iris reference shots yet: that needs a GUI session for Iris (FEATURES 4y (a)).

Frame time (1280x720, noon, still, 20 s, p50 / p95):

M4 Pro (Metal) RTX 4080 (Vulkan)
vanilla 1.31 / 1.48 ms 0.16 / 0.18 ms
MakeUp Ultra Fast 4.41 / 4.83 ms 0.72 / 0.74 ms
Chocapic13' 4.48 / 4.75 ms 0.85 / 0.91 ms
BSL 4.66 / 4.99 ms 0.89 / 1.08 ms

RTX 4080: Linux build from the ThinkPad, offscreen in a virtual screen while the desktop was idle (GPU 0%). Each run was done twice in alternating order, with vanilla at the start, middle and end (0.15–0.16 ms); the two runs were within 0.01 ms of each other. A water view of Chocapic13' and MakeUp on Vulkan is here.

The Mac mini was 85–95% CPU-busy with other sessions during the run, and vanilla was repeated at the end (1.30 ms). MakeUp cost 2.20 ms on the same machine before this PR, without its terrain programs. The rise is mostly the pack's own forward lighting in gbuffers_terrain. Vertex pulling costs about 0.2 ms, and culling makes no difference on the Mac.

Tests

  • cargo test -p horizon-shaderpack: covers the geometry mode with its glue, the switch fix and block.properties ids.
  • cargo test -p horizon-client java:
    • the glue and the atlas compile to MSL, SPIR-V and HLSL;
    • sprites get their block ids;
    • real_packs_load covers the terrain programs of MakeUp, Chocapic13', BSL and Photon with HORIZON_TEST_SHADERPACKS.
  • cargo clippy and cargo fmt are clean.

Not yet (FEATURES 4y (h))

  • Entities, sky, hand, weather, clouds and particles are still Horizon's, written to colortex0 only.
  • The packs' shadow program does not run yet.
  • GPU occlusion culling is off while a pack draws terrain.
  • Block ids come from sprite names, not block states.
  • LOD tile UVs are clamped.
  • Only the overworld has been checked, on Metal and Vulkan.

🤖 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/1277 **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-gbuffers-terrain` --- ### 📝 Commits (3) - [`6a58fc2`](https://github.com/horizon-rust/horizon/commit/6a58fc20dadaeed3e0e0af151c5b8ad59ca84c60) Java shader packs: the pack's gbuffers_terrain and gbuffers_water draw the terrain - [`0f3a92a`](https://github.com/horizon-rust/horizon/commit/0f3a92ac2bae7ba304c3e7e7ca39b0f1bf6ef5e5) Merge feat/java-packs-photon-chocapic into feat/java-gbuffers-terrain - [`c924894`](https://github.com/horizon-rust/horizon/commit/c924894624288f6289d1aabb5a91e25a3e21ceb6) Merge remote-tracking branch 'origin/main' into feat/java-gbuffers-terrain ### 📊 Changes **15 files changed** (+2257 additions, -202 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` (+214 -13) 📝 `crates/horizon-client/src/gfx/animate.rs` (+6 -0) 📝 `crates/horizon-client/src/gfx/arena.rs` (+8 -1) 📝 `crates/horizon-client/src/gfx/flat.rs` (+10 -1) 📝 `crates/horizon-client/src/gfx/java_stages.rs` (+743 -146) ➕ `crates/horizon-client/src/gfx/java_terrain.rs` (+645 -0) 📝 `crates/horizon-client/src/java_pack.rs` (+138 -5) 📝 `crates/horizon-shaderpack/src/lib.rs` (+16 -0) 📝 `crates/horizon-shaderpack/src/pipeline.rs` (+109 -1) 📝 `crates/horizon-shaderpack/src/properties.rs` (+88 -0) 📝 `crates/horizon-shaderpack/src/translate.rs` (+142 -16) 📝 `crates/horizon-shaderpack/tests/translate.rs` (+90 -1) 📝 `docs/shader-packs.md` (+39 -16) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1267 (`feat/java-packs-photon-chocapic`): review that one first; this diff is only the terrain piece. ## What Java shader packs now draw Horizon's terrain with their own `gbuffers_terrain` and `gbuffers_water`, as Iris does, instead of only post-processing Horizon's world. - **Translator, geometry mode** (`horizon-shaderpack/src/translate.rs`): the pack's bindings move to group 2, its vertex attributes become globals that a glue function fills before `main`, and fragments under `alphaTestRef` (0.1) are discarded. A new IR pass ends switch cases that return. Without it, naga's WGSL writer rejects Photon's terrain program ("fall-through switch case block"). - **Glue** (`gfx/java_terrain.rs`): the pack's vertex program reads Horizon's own terrain vertices from the arena pages, through both the instanced and the flat draws. The glue decodes them into Iris's attributes: - `vaPosition`/`gl_Vertex` relative to the camera; - colour with vanilla's face shade undone; - UV, lightmap 0..240; - normal and `at_tangent` from the quad's four corners; - `mc_midTexCoord`, `at_midBlock`; - `mc_Entity.x` from the pack's `block.properties`, matched to each sprite's block by name. - **Textures:** `gtexture` is a 2D atlas built once from Horizon's sprite arrays; animated sprites are copied in each frame. `lightmap` is Horizon's lightmap with Iris's texture matrix. - **Order** (`gfx/java_stages.rs`): 1. Horizon's world pass skips its own terrain. 2. At `world_at`, after the rest of the world enters `colortex0` and depth, the terrain program draws into the pack's `RENDERTARGETS` and the depth goes into `depthtex0`/`depthtex1`. 3. Before the first `composite`, `gbuffers_water` draws the translucent layer with the pack's `blend.*` (or vanilla's) and the depth goes into `depthtex0`. - **16-bit targets:** `RGBA16`/`RG16`/`R16` targets are 16-bit unorm where the adapter can render and filter them (`TEXTURE_FORMAT_16BIT_NORM` plus adapter-specific format features). Chocapic13' packs its G-buffer into RGBA16, and with half floats its leaves came out red-dotted. - **Fallback:** a pack whose terrain programs fail to compile warns and falls back to the full-screen-only path. - **Docs:** `docs/shader-packs.md` (status, how it works, limits, compatibility rows). ## Proof Screenshots are on the `screenshots/shaders-1` branch, folder [`java-terrain/`](https://github.com/ludovic111/horizon/tree/screenshots/shaders-1/java-terrain). They show seed 42 at (-30,100,0), yaw 270, pitch 25. Columns are times 1000 / 6000 / 12400 / 18000 plus a water view at 6000. Rows are vanilla / MakeUp Ultra Fast 9.6 / Chocapic13' V9 High / BSL v10.1.8 / Photon v1.4: ![grid](https://raw.githubusercontent.com/ludovic111/horizon/screenshots/shaders-1/java-terrain/grid_terrain.jpg) MakeUp, Chocapic13' and BSL now show their own terrain lighting, water and fog. Photon still draws black: its sky and light come from a compute pass and `.dat` look-up tables, which is the next piece. No Iris reference shots yet: that needs a GUI session for Iris (FEATURES 4y (a)). Frame time (1280x720, noon, still, 20 s, p50 / p95): | | M4 Pro (Metal) | RTX 4080 (Vulkan) | | --- | --- | --- | | vanilla | 1.31 / 1.48 ms | 0.16 / 0.18 ms | | MakeUp Ultra Fast | 4.41 / 4.83 ms | 0.72 / 0.74 ms | | Chocapic13' | 4.48 / 4.75 ms | 0.85 / 0.91 ms | | BSL | 4.66 / 4.99 ms | 0.89 / 1.08 ms | RTX 4080: Linux build from the ThinkPad, offscreen in a virtual screen while the desktop was idle (GPU 0%). Each run was done twice in alternating order, with vanilla at the start, middle and end (0.15–0.16 ms); the two runs were within 0.01 ms of each other. A water view of Chocapic13' and MakeUp on Vulkan is [here](https://github.com/ludovic111/horizon/blob/screenshots/shaders-1/java-terrain/rtx4080_choca_makeup_water.jpg). The Mac mini was 85–95% CPU-busy with other sessions during the run, and vanilla was repeated at the end (1.30 ms). MakeUp cost 2.20 ms on the same machine before this PR, without its terrain programs. The rise is mostly the pack's own forward lighting in `gbuffers_terrain`. Vertex pulling costs about 0.2 ms, and culling makes no difference on the Mac. ## Tests - `cargo test -p horizon-shaderpack`: covers the geometry mode with its glue, the switch fix and `block.properties` ids. - `cargo test -p horizon-client java`: - the glue and the atlas compile to MSL, SPIR-V and HLSL; - sprites get their block ids; - `real_packs_load` covers the terrain programs of MakeUp, Chocapic13', BSL and Photon with `HORIZON_TEST_SHADERPACKS`. - `cargo clippy` and `cargo fmt` are clean. ## Not yet (FEATURES 4y (h)) - Entities, sky, hand, weather, clouds and particles are still Horizon's, written to `colortex0` only. - The packs' `shadow` program does not run yet. - GPU occlusion culling is off while a pack draws terrain. - Block ids come from sprite names, not block states. - LOD tile UVs are clamped. - Only the overworld has been checked, on Metal and Vulkan. 🤖 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:48 +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#3475
No description provided.