[PR #2021] [MERGED] HDR output: scRGB swapchain, HDR metadata and emissive highlights #3944

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

📋 Pull Request Information

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

Base: main ← Head: hdr-output


📝 Commits (4)

  • 9b863d6 HDR output: scRGB swapchain, HDR metadata and emissive highlights
  • 728c6a6 HDR: the emission mark in the vertex colour's alpha, not a layer bit
  • 92ed365 Merge main into hdr-output
  • caae026 HDR: keep native material packs' vertex tint opaque

📊 Changes

19 files changed (+652 additions, -39 deletions)

View changed files

📝 Cargo.lock (+9 -0)
📝 Cargo.toml (+1 -1)
📝 crates/horizon-client/Cargo.toml (+1 -0)
📝 crates/horizon-client/examples/probe/section_mesh_fixture.rs (+10 -2)
📝 crates/horizon-client/src/game/options.rs (+5 -0)
📝 crates/horizon-client/src/gfx.rs (+134 -22)
➕ crates/horizon-client/src/gfx/hdr.rs (+222 -0)
📝 crates/horizon-client/src/gfx/native_material.rs (+1 -1)
📝 crates/horizon-client/src/gfx/pack_atlas.rs (+2 -1)
📝 crates/horizon-client/src/graphics.rs (+19 -1)
📝 crates/horizon-client/src/graphics_ui.rs (+27 -0)
➕ crates/horizon-client/src/hdr.wgsl (+69 -0)
📝 crates/horizon-client/src/mesher.rs (+17 -1)
📝 crates/horizon-client/src/mesher/fluid.rs (+4 -1)
📝 crates/horizon-client/src/terrain.wgsl (+8 -2)
📝 crates/horizon-client/src/world_post.wgsl (+7 -5)
➕ crates/horizon-hdr/Cargo.toml (+17 -0)
➕ crates/horizon-hdr/src/lib.rs (+95 -0)
📝 docs/graphics.md (+4 -2)

📄 Description

🤖 Opened by Senjin's AI agent (Claude Code), not by Senjin.

What and why

HDR output for HDR monitors (roadmap "HDR monitors", #1441), off by default, in Graphics > Display:

  • HDR: presents to an scRGB swapchain (Rgba16Float, ExtendedSrgbLinear) where the surface offers it.
  • Paper White: where SDR white sits. At the default it matches SDR mode on KWin.
  • Peak Brightness: how far light sources may go above it.

The image is drawn exactly as today, into an 8-bit target in vanilla's gamma space, so blending, UI and
fog are untouched. One final pass (hdr.wgsl) decodes it (gamma 2.2) to linear light at the paper white
and writes the swapchain. Light sources (blocks with light emission, lava, the sun and the moon) are lifted
evenly towards the peak; everything else stays as in SDR.

How it works:

  • Emissive mask. The mesher puts the light level a face emits (0 to 15, lava 15) in its vertex
    colour's alpha byte, which was always 0xFF: the low four bits hold 15 minus the level
    (EMISSION_BITS), so 0xFF still means none and every other vertex source is unchanged.
    terrain.wgsl takes the colour's rgb only, and writes alpha 0 for emitting faces' pixels; the
    celestial pipeline writes alpha 0 for the sun and moon. The lift doesn't use the level yet; it is
    there for a later step to set how far each light source rises. The frame's
    alpha was otherwise unused. The world is copied aside before the hand and HUD, and only pixels that
    still show it (or show it evenly darkened, as the vignette does) and are marked can be lifted.
  • Even lift, not a highlight curve. Vanilla's textures were drawn for SDR: a curve on the brightest
    pixels blows out near-white spots (glowstone) while lava and a jack o'lantern's face barely change. A
    marked pixel above a brightness threshold gets 70% of the headroom; dimmer parts (lava's crust, a
    lantern's metal) get less, down to none.
  • HDR metadata. wgpu sets none. Without it, NVIDIA's Wayland driver describes an scRGB window to the
    compositor only as set_luminances(0, 80, 203), and KWin 6.8 then takes 80 nits (scRGB 1.0) as the
    content's maximum and clips everything above it: whites turn grey and bright colours lose their hue. A
    small new crate, horizon-hdr, opens the Vulkan device with VK_EXT_hdr_metadata when the GPU offers
    it and sends MaxCLL and mastering luminance after every swapchain configure. It holds the unsafe calls
    because horizon-client forbids unsafe code, the same pattern as horizon-threads. With it the driver
    forwards set_max_cll and set_mastering_luminance, and KWin stops clipping.

Part of #1441: tested on Linux only (see Testing). Windows (DX12/Vulkan) and macOS use the same wgpu
colour space, but are untested. On the OpenGL fallback wgpu offers no scRGB surface, so HDR stays
unavailable there.

At ~680 lines this is over the usual size: the output, the metadata and the highlights only make sense
together. Happy to split it if you prefer.

Vanilla reference

Horizon-only. Off by default; with HDR off nothing changes for players. The only shared changes are the
vertex colour's alpha byte and alpha values in the frame, neither of which anything read before;
the sprite layer keeps all its bits. section_mesh_fixture restores vanilla's 0xFF alpha before
comparing, and Java shader packs get the vertex colour with alpha 1, as before.

Self-check

pr_ready (tools/pr_ready.py --quick, against origin/main at 57c5f8129, Rust 1.99.1)

Check Result
Scope ⚠️ 18 files, +651 −38; 683 lines of code: over 500 (see above)
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅
clippy ✅
tests: workspace ✅ 2176 passed
doc tests ✅ 1 passed
Parity ➖ 338 affected, to run in CI

horizon-hdr also passes cargo clippy -- -D warnings for x86_64-pc-windows-gnu and aarch64-apple-darwin.

Testing

Linux, KWin 6.8.1 (Plasma HDR on, SDR brightness 430 nits), NVIDIA RTX 2080 (driver 615.78), Alienware
AW3423DW QD-OLED (HDR1000, EDID peak 1060 nits, max average 254 nits):

  • HDR on, Paper White 200: identical to SDR (small white text on a black screen, toggled back and forth).
  • Before the metadata: whites grey, contrast lost, sky shifted green as Paper White rose. After: none of it.
  • Protocol log (WAYLAND_DEBUG=client) shows the driver sending set_max_cll and
    set_mastering_luminance once the metadata is set.
  • Torches, lava, glowstone, jack o'lanterns, lanterns and the sun lift visibly; sheep, white flowers and
    cloud edges in midday sun do not.

A debug view, HORIZON_HDR_DEBUG=1, paints lifted pixels magenta, to check what the mask selects.

Screenshots

HDR can't be shown in an SDR screenshot; the debug view above is the way to see what it does.

Open questions

  • What the sliders mean. KWin maps the content's reference white (203 nits) onto the user's SDR
    brightness, so on Linux the nits shown are relative to the desktop, while on Windows scRGB is absolute.
    Here Paper White 200 / Peak 500 matched the tester's Windows calibration of 400 / 1000. A relative
    scale (100% = desktop white, peak as a multiple of it) may suit both better, and the compositor's
    preferred reference and peak could be read with wp_color_management_surface_feedback_v1.
  • Known gaps: flame and other glowing particles aren't marked (they share the blended entity
    pipeline); distant LOD terrain isn't flagged; shader packs may write their own alpha.
  • The F-key toggle used for testing is not included.
  • Possible next steps, after this one: a separate UI brightness next to Paper White (the HDR pass
    already tells HUD pixels from the world) and a black level for LCDs (the metadata's minimum
    luminance, now 0); a key to reach the HDR settings in game (the sliders already apply live); HDR10/PQ
    output (Bt2100Pq on a 10-bit swapchain; the NVIDIA driver offers it on Wayland too, next to
    scRGB): half the bandwidth of the fp16 swapchain; HDR screenshots. The look in
    the screenshots linked from #1441 comes from shader-pack lighting above SDR white: that is full HDR
    lighting with tone mapping, a later step on top of this output layer.

🤖 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/2021 **Author:** [@senjinthedragon](https://github.com/senjinthedragon) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `hdr-output` --- ### 📝 Commits (4) - [`9b863d6`](https://github.com/horizon-rust/horizon/commit/9b863d60935c3a5730d372383a9f4e60632e1848) HDR output: scRGB swapchain, HDR metadata and emissive highlights - [`728c6a6`](https://github.com/horizon-rust/horizon/commit/728c6a62b39a992761335855d10ec405d7ac8a87) HDR: the emission mark in the vertex colour's alpha, not a layer bit - [`92ed365`](https://github.com/horizon-rust/horizon/commit/92ed365a19967844fd78cbdedce0a13eb5fbd42a) Merge main into hdr-output - [`caae026`](https://github.com/horizon-rust/horizon/commit/caae0264166b58489614f48941858729719ea4f5) HDR: keep native material packs' vertex tint opaque ### 📊 Changes **19 files changed** (+652 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+9 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/horizon-client/Cargo.toml` (+1 -0) 📝 `crates/horizon-client/examples/probe/section_mesh_fixture.rs` (+10 -2) 📝 `crates/horizon-client/src/game/options.rs` (+5 -0) 📝 `crates/horizon-client/src/gfx.rs` (+134 -22) ➕ `crates/horizon-client/src/gfx/hdr.rs` (+222 -0) 📝 `crates/horizon-client/src/gfx/native_material.rs` (+1 -1) 📝 `crates/horizon-client/src/gfx/pack_atlas.rs` (+2 -1) 📝 `crates/horizon-client/src/graphics.rs` (+19 -1) 📝 `crates/horizon-client/src/graphics_ui.rs` (+27 -0) ➕ `crates/horizon-client/src/hdr.wgsl` (+69 -0) 📝 `crates/horizon-client/src/mesher.rs` (+17 -1) 📝 `crates/horizon-client/src/mesher/fluid.rs` (+4 -1) 📝 `crates/horizon-client/src/terrain.wgsl` (+8 -2) 📝 `crates/horizon-client/src/world_post.wgsl` (+7 -5) ➕ `crates/horizon-hdr/Cargo.toml` (+17 -0) ➕ `crates/horizon-hdr/src/lib.rs` (+95 -0) 📝 `docs/graphics.md` (+4 -2) </details> ### 📄 Description > 🤖 Opened by Senjin's AI agent (Claude Code), not by Senjin. ## What and why HDR output for HDR monitors (roadmap "HDR monitors", #1441), off by default, in Graphics > Display: - **HDR**: presents to an scRGB swapchain (`Rgba16Float`, `ExtendedSrgbLinear`) where the surface offers it. - **Paper White**: where SDR white sits. At the default it matches SDR mode on KWin. - **Peak Brightness**: how far light sources may go above it. The image is drawn exactly as today, into an 8-bit target in vanilla's gamma space, so blending, UI and fog are untouched. One final pass (`hdr.wgsl`) decodes it (gamma 2.2) to linear light at the paper white and writes the swapchain. Light sources (blocks with light emission, lava, the sun and the moon) are lifted evenly towards the peak; everything else stays as in SDR. How it works: - **Emissive mask.** The mesher puts the light level a face emits (0 to 15, lava 15) in its vertex colour's alpha byte, which was always 0xFF: the low four bits hold 15 minus the level (`EMISSION_BITS`), so 0xFF still means none and every other vertex source is unchanged. `terrain.wgsl` takes the colour's rgb only, and writes alpha 0 for emitting faces' pixels; the celestial pipeline writes alpha 0 for the sun and moon. The lift doesn't use the level yet; it is there for a later step to set how far each light source rises. The frame's alpha was otherwise unused. The world is copied aside before the hand and HUD, and only pixels that still show it (or show it evenly darkened, as the vignette does) and are marked can be lifted. - **Even lift, not a highlight curve.** Vanilla's textures were drawn for SDR: a curve on the brightest pixels blows out near-white spots (glowstone) while lava and a jack o'lantern's face barely change. A marked pixel above a brightness threshold gets 70% of the headroom; dimmer parts (lava's crust, a lantern's metal) get less, down to none. - **HDR metadata.** wgpu sets none. Without it, NVIDIA's Wayland driver describes an scRGB window to the compositor only as `set_luminances(0, 80, 203)`, and KWin 6.8 then takes 80 nits (scRGB 1.0) as the content's maximum and clips everything above it: whites turn grey and bright colours lose their hue. A small new crate, `horizon-hdr`, opens the Vulkan device with `VK_EXT_hdr_metadata` when the GPU offers it and sends MaxCLL and mastering luminance after every swapchain configure. It holds the unsafe calls because `horizon-client` forbids unsafe code, the same pattern as `horizon-threads`. With it the driver forwards `set_max_cll` and `set_mastering_luminance`, and KWin stops clipping. Part of #1441: tested on Linux only (see Testing). Windows (DX12/Vulkan) and macOS use the same wgpu colour space, but are untested. On the OpenGL fallback wgpu offers no scRGB surface, so HDR stays unavailable there. At ~680 lines this is over the usual size: the output, the metadata and the highlights only make sense together. Happy to split it if you prefer. ## Vanilla reference Horizon-only. Off by default; with HDR off nothing changes for players. The only shared changes are the vertex colour's alpha byte and alpha values in the frame, neither of which anything read before; the sprite layer keeps all its bits. `section_mesh_fixture` restores vanilla's 0xFF alpha before comparing, and Java shader packs get the vertex colour with alpha 1, as before. ## Self-check **pr_ready** (`tools/pr_ready.py --quick`, against origin/main at 57c5f8129, Rust 1.99.1) | Check | Result | | --- | --- | | Scope | ⚠️ 18 files, +651 −38; 683 lines of code: over 500 (see above) | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ | | clippy | ✅ | | tests: workspace | ✅ 2176 passed | | doc tests | ✅ 1 passed | | Parity | ➖ 338 affected, to run in CI | `horizon-hdr` also passes `cargo clippy -- -D warnings` for `x86_64-pc-windows-gnu` and `aarch64-apple-darwin`. ## Testing Linux, KWin 6.8.1 (Plasma HDR on, SDR brightness 430 nits), NVIDIA RTX 2080 (driver 615.78), Alienware AW3423DW QD-OLED (HDR1000, EDID peak 1060 nits, max average 254 nits): - HDR on, Paper White 200: identical to SDR (small white text on a black screen, toggled back and forth). - Before the metadata: whites grey, contrast lost, sky shifted green as Paper White rose. After: none of it. - Protocol log (`WAYLAND_DEBUG=client`) shows the driver sending `set_max_cll` and `set_mastering_luminance` once the metadata is set. - Torches, lava, glowstone, jack o'lanterns, lanterns and the sun lift visibly; sheep, white flowers and cloud edges in midday sun do not. A debug view, `HORIZON_HDR_DEBUG=1`, paints lifted pixels magenta, to check what the mask selects. ## Screenshots HDR can't be shown in an SDR screenshot; the debug view above is the way to see what it does. ## Open questions - **What the sliders mean.** KWin maps the content's reference white (203 nits) onto the user's SDR brightness, so on Linux the nits shown are relative to the desktop, while on Windows scRGB is absolute. Here Paper White 200 / Peak 500 matched the tester's Windows calibration of 400 / 1000. A relative scale (100% = desktop white, peak as a multiple of it) may suit both better, and the compositor's preferred reference and peak could be read with `wp_color_management_surface_feedback_v1`. - **Known gaps**: flame and other glowing particles aren't marked (they share the blended entity pipeline); distant LOD terrain isn't flagged; shader packs may write their own alpha. - **The F-key toggle** used for testing is not included. - **Possible next steps**, after this one: a separate UI brightness next to Paper White (the HDR pass already tells HUD pixels from the world) and a black level for LCDs (the metadata's minimum luminance, now 0); a key to reach the HDR settings in game (the sliders already apply live); HDR10/PQ output (`Bt2100Pq` on a 10-bit swapchain; the NVIDIA driver offers it on Wayland too, next to scRGB): half the bandwidth of the fp16 swapchain; HDR screenshots. The look in the screenshots linked from #1441 comes from shader-pack lighting above SDR white: that is full HDR lighting with tone mapping, a later step on top of this output layer. 🤖 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:13:27 +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#3944
No description provided.