[GH-ISSUE #3125] HDR and Horizon's shader packs: material stage drops light-source marks, post alpha, an HDR output for packs #827

Open
opened 2026-11-02 15:42:12 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @senjinthedragon on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3125

🤖 Written by Senjin's AI agent (Claude Code), posted by Senjin.

Part of #1441. HDR output and Horizon's own shader packs (.hshader, docs/shaders.md) meet in two places today, and a third is worth agreeing on before the pack API leaves 0.1.

How HDR output finds what shines

The HDR pass (hdr.wgsl) lifts only the pixels of light sources. Terrain (fs_solid), particles (fs_hdr_mark) and the sun and moon (fs_sky_celestial) mark those pixels in the world frame's alpha: anything below 0.75 is a light source, and the value says how much it shines. Everything else in the world target has alpha 1, and nothing else reads that alpha. The world is copied for the HDR pass after the post passes (Hdr::keep_world), so it sees the picture as the pack left it.

1. A material stage drops the marks

horizon_material_fs_solid (gfx/native_material.rs) writes vec4(color.rgb, 1.0). With a pack that has a material stage, no light source on terrain shines in HDR: torches, lava and glowstone stay at SDR brightness, while particles and the sun still shine.

The mark depends only on the block's emission and its unlit texel, both of which the wrapper already has (in.layer, the sprite it samples), so it could apply the mark after material() just as fs_solid does. The pack decides the colour, and Horizon still knows which pixels are light sources. That's a small change, and I can send it once the light-source PRs it builds on (#2705 and the ones after it) are in.

2. Post passes have to pass alpha through

A post pass returns a vec4, and its alpha becomes the world frame's alpha. The example pack does the right thing (grade.wgsl and glow.wgsl return input.color.a), but nothing says a pack must:

  • A pass that returns alpha 1 turns HDR's light sources off.
  • A pass that returns some other value makes random pixels shine.

I'd add a line to PostInput.color and the post section of docs/shaders.md: "Return input.color.a as your alpha: Horizon's HDR output reads it to find light sources." A check that warns when a post stage's return alpha doesn't come from input.color.a might be possible too, but the docs line is the cheap part.

3. An HDR output for packs (a proposal for the API)

Passes before the last already write half-float targets, so values over 1 carry. The last pass draws onto the 8-bit frame, though, so a pack can't make anything brighter than paper white. With HDR on, the pack can only grade an SDR picture, and Horizon's light-source lift goes on top.

A way to let packs own HDR:

  • Frame fields:
    • hdr: 0 off, 1 on
    • paper_white: paper white in nits
    • peak: the peak in nits
  • An opt-in in horizon-shaders.toml (say [post] hdr = true): with HDR on, the last pass writes a half-float target where 1.0 is paper white and values above go into the headroom, up to peak / paper_white. The HDR pass then only encodes it (scRGB or PQ), with no lift, because the pack decided what shines.
  • Without the opt-in, everything stays as it is today, so existing packs keep working.

That's a design decision for the pack API, so I'm putting it up for discussion rather than as a PR.

And when shaders/-format packs come back

The clean-room loader for the Iris/OptiFine format will have the same question as point 2: those packs use the frame's alpha for their own purposes. Unless the loader keeps Horizon's marks, the simple rule is that while such a pack runs, the HDR pass skips the light-source lift and only maps the picture to paper white. That keeps a pack from shining at random.

Originally created by @senjinthedragon on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3125 > 🤖 Written by Senjin's AI agent (Claude Code), posted by Senjin. Part of #1441. HDR output and Horizon's own shader packs (`.hshader`, [docs/shaders.md](docs/shaders.md)) meet in two places today, and a third is worth agreeing on before the pack API leaves 0.1. ## How HDR output finds what shines The HDR pass (`hdr.wgsl`) lifts only the pixels of light sources. Terrain (`fs_solid`), particles (`fs_hdr_mark`) and the sun and moon (`fs_sky_celestial`) mark those pixels in the world frame's alpha: anything below 0.75 is a light source, and the value says how much it shines. Everything else in the world target has alpha 1, and nothing else reads that alpha. The world is copied for the HDR pass after the post passes (`Hdr::keep_world`), so it sees the picture as the pack left it. ## 1. A material stage drops the marks `horizon_material_fs_solid` (`gfx/native_material.rs`) writes `vec4(color.rgb, 1.0)`. With a pack that has a material stage, no light source on terrain shines in HDR: torches, lava and glowstone stay at SDR brightness, while particles and the sun still shine. The mark depends only on the block's emission and its unlit texel, both of which the wrapper already has (`in.layer`, the sprite it samples), so it could apply the mark after `material()` just as `fs_solid` does. The pack decides the colour, and Horizon still knows which pixels are light sources. That's a small change, and I can send it once the light-source PRs it builds on (#2705 and the ones after it) are in. ## 2. Post passes have to pass alpha through A post pass returns a `vec4`, and its alpha becomes the world frame's alpha. The example pack does the right thing (`grade.wgsl` and `glow.wgsl` return `input.color.a`), but nothing says a pack must: - A pass that returns alpha 1 turns HDR's light sources off. - A pass that returns some other value makes random pixels shine. I'd add a line to `PostInput.color` and the post section of [docs/shaders.md](docs/shaders.md): "Return `input.color.a` as your alpha: Horizon's HDR output reads it to find light sources." A check that warns when a post stage's return alpha doesn't come from `input.color.a` might be possible too, but the docs line is the cheap part. ## 3. An HDR output for packs (a proposal for the API) Passes before the last already write half-float targets, so values over 1 carry. The last pass draws onto the 8-bit frame, though, so a pack can't make anything brighter than paper white. With HDR on, the pack can only grade an SDR picture, and Horizon's light-source lift goes on top. A way to let packs own HDR: - **`Frame` fields:** - `hdr`: 0 off, 1 on - `paper_white`: paper white in nits - `peak`: the peak in nits - **An opt-in in `horizon-shaders.toml`** (say `[post] hdr = true`): with HDR on, the last pass writes a half-float target where 1.0 is paper white and values above go into the headroom, up to `peak / paper_white`. The HDR pass then only encodes it (scRGB or PQ), with no lift, because the pack decided what shines. - **Without the opt-in**, everything stays as it is today, so existing packs keep working. That's a design decision for the pack API, so I'm putting it up for discussion rather than as a PR. ## And when `shaders/`-format packs come back The clean-room loader for the Iris/OptiFine format will have the same question as point 2: those packs use the frame's alpha for their own purposes. Unless the loader keeps Horizon's marks, the simple rule is that while such a pack runs, the HDR pass skips the light-source lift and only maps the picture to paper white. That keeps a pack from shining at random.
Author
Owner

@senjinthedragon commented on GitHub (Nov 2, 2026):

🤖 Agent: Parts 1 and 2 are done: a material stage keeps the light sources' marks (#6530), and the docs tell post passes to return input.color.a (in #6530 too). Part 3, an HDR output for packs, is still open and is where LabPBR emission belongs: we tried reading it without a shader pack, and packs paint it for bloom, so it can't look as intended there. Leaving this open for that, for when a pack author wants it.

<!-- gh-comment-id:6574714159 --> @senjinthedragon commented on GitHub (Nov 2, 2026): 🤖 Agent: Parts 1 and 2 are done: a material stage keeps the light sources' marks (#6530), and the docs tell post passes to return input.color.a (in #6530 too). Part 3, an HDR output for packs, is still open and is where LabPBR emission belongs: we tried reading it without a shader pack, and packs paint it for bloom, so it can't look as intended there. Leaving this open for that, for when a pack author wants it.
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#827
No description provided.