[GH-ISSUE #3734] Shader API: give post passes depth and colour from before translucent terrain, and a water mask #1071

Open
opened 2026-11-02 15:44:01 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @TmBrnr on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3734

🤖 Filed by TmBrnr's AI agent (Claude Code), not by TmBrnr directly.

What

Three new, opt-in inputs for [[post]] passes in Horizon's native shader packs (API 0.1), so a pack can draw realistic water: reflections of the world, colour that deepens with depth, and refraction.

Binding (group 3) Declaration Meaning
6 var opaque_depth: texture_depth_2d The world's depth before translucent terrain (water, stained glass, ice) was drawn. Reversed, as scene_depth.
7 var opaque_color: texture_2d<f32> The world's picture before translucent terrain was drawn.
8 var surface: texture_2d<u32> What translucent terrain is in front at each pixel: 0 none, 1 water, 2 other translucent terrain.

Plus a helper, fn surface_at(uv: vec2<f32>) -> u32, beside depth_at.

Why

Today a post pass sees only the final picture and depth. Water writes depth, so scene_depth is the water's surface and nothing under it, and no input says which pixels are water. The material stage can shade water, but it can't see the rest of the scene. I built a test pack on 0.1 (screen-space sun shadows, sun shading, light shafts, haze): everything works except water, which can only reflect a guessed sky colour, so it looks painted on. With these three inputs, a pack can trace reflections over the screen where surface == 1, set colour and clarity from scene_depth vs opaque_depth, and offset its opaque_color lookups for refraction.

How (proposal)

  • Free when unused. The game copies or allocates nothing unless a pass reads one of the new bindings. I'd detect that from the checked naga module: does the stage's code reference the global? That avoids a manifest key. If you'd rather have it explicit, a manifest opt-in in the shape #3125 suggests works too.
  • Opaque depth and colour. When needed, the world pass ends just before translucent terrain, copies its depth and colour, and continues in a new pass that loads both. This is the point where pack_post.rs already copies depthtex1 for the other pack format.
  • Surface mask. Translucent terrain draws in that new pass with a second R8Uint target. The terrain fragment writes 1 for water sprites and 2 otherwise, from a small table of which atlas layers are water (still, flowing, overlay). The pass after translucent terrain goes back to the single target. Only the native material translucent pipeline gets the two-target variant.
  • Material stage (optional, same change or later). MaterialInput.water: bool, from the same table, so the material stage can shade water without guessing from tint.
  • Compatibility. Additive, so 0.1.0 → 0.1.1 per docs/api/stability.md. scene_color, scene_depth and PostInput keep their meaning. opaque_color keeps alpha as written, so the HDR light-mark contract in #3125 holds. Budgets unchanged.
  • Docs. Regenerated docs/api/shaders-reference.md, a section in docs/shaders.md, and a changelog line in docs/api/shaders.md. The example pack or a test pass exercises the new inputs.

Plan

Two PRs, each under ~500 lines:

  1. opaque_depth and opaque_color: API + check + renderer split/copy when used + docs.
  2. surface (and MaterialInput.water): the water-layer table, the two-target translucent variant, API + docs.

Before/after GPU time with F3, with and without a pack reading the inputs; no change without a pack.

Questions

  1. Usage detection vs a manifest flag?
  2. Names: opaque_*, or something closer to how you'd name a future G-buffer?
  3. Should the surface mask carry more kinds now (ice, glass, slime/honey, lava) or start with water?
  4. Is this something you'd want, or would you rather it wait for the planned lighting stage?
Originally created by @TmBrnr on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3734 > 🤖 Filed by TmBrnr's AI agent (Claude Code), not by TmBrnr directly. ## What Three new, opt-in inputs for `[[post]]` passes in Horizon's native shader packs (API 0.1), so a pack can draw realistic water: reflections of the world, colour that deepens with depth, and refraction. | Binding (group 3) | Declaration | Meaning | | --- | --- | --- | | 6 | `var opaque_depth: texture_depth_2d` | The world's depth before translucent terrain (water, stained glass, ice) was drawn. Reversed, as `scene_depth`. | | 7 | `var opaque_color: texture_2d<f32>` | The world's picture before translucent terrain was drawn. | | 8 | `var surface: texture_2d<u32>` | What translucent terrain is in front at each pixel: 0 none, 1 water, 2 other translucent terrain. | Plus a helper, `fn surface_at(uv: vec2<f32>) -> u32`, beside `depth_at`. ## Why Today a post pass sees only the final picture and depth. Water writes depth, so `scene_depth` is the water's surface and nothing under it, and no input says which pixels are water. The material stage can shade water, but it can't see the rest of the scene. I built a test pack on 0.1 (screen-space sun shadows, sun shading, light shafts, haze): everything works except water, which can only reflect a guessed sky colour, so it looks painted on. With these three inputs, a pack can trace reflections over the screen where `surface == 1`, set colour and clarity from `scene_depth` vs `opaque_depth`, and offset its `opaque_color` lookups for refraction. ## How (proposal) - **Free when unused.** The game copies or allocates nothing unless a pass reads one of the new bindings. I'd detect that from the checked naga module: does the stage's code reference the global? That avoids a manifest key. If you'd rather have it explicit, a manifest opt-in in the shape #3125 suggests works too. - **Opaque depth and colour.** When needed, the world pass ends just before translucent terrain, copies its depth and colour, and continues in a new pass that loads both. This is the point where `pack_post.rs` already copies `depthtex1` for the other pack format. - **Surface mask.** Translucent terrain draws in that new pass with a second `R8Uint` target. The terrain fragment writes 1 for water sprites and 2 otherwise, from a small table of which atlas layers are water (still, flowing, overlay). The pass after translucent terrain goes back to the single target. Only the native material translucent pipeline gets the two-target variant. - **Material stage (optional, same change or later).** `MaterialInput.water: bool`, from the same table, so the material stage can shade water without guessing from tint. - **Compatibility.** Additive, so 0.1.0 → 0.1.1 per `docs/api/stability.md`. `scene_color`, `scene_depth` and `PostInput` keep their meaning. `opaque_color` keeps alpha as written, so the HDR light-mark contract in #3125 holds. Budgets unchanged. - **Docs.** Regenerated `docs/api/shaders-reference.md`, a section in `docs/shaders.md`, and a changelog line in `docs/api/shaders.md`. The example pack or a test pass exercises the new inputs. ## Plan Two PRs, each under ~500 lines: 1. `opaque_depth` and `opaque_color`: API + check + renderer split/copy when used + docs. 2. `surface` (and `MaterialInput.water`): the water-layer table, the two-target translucent variant, API + docs. Before/after GPU time with F3, with and without a pack reading the inputs; no change without a pack. ## Questions 1. Usage detection vs a manifest flag? 2. Names: `opaque_*`, or something closer to how you'd name a future G-buffer? 3. Should the surface mask carry more kinds now (ice, glass, slime/honey, lava) or start with water? 4. Is this something you'd want, or would you rather it wait for the planned lighting stage?
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#1071
No description provided.