From 620dfc6e0d53f0d32d75b791009ecbd923b92114 Mon Sep 17 00:00:00 2001 From: Senjin Date: Tue, 27 Oct 2026 05:01:43 +0100 Subject: [PATCH] HDR: let light sources shine the same under the vignette The lift's threshold read the frame, which the vignette darkens toward the screen's edges, so a jack o'lantern lit up fully in the middle of the screen and only at its eyes and mouth further out. Read it from the world copy instead; the gain still applies to the frame, so the vignette darkens highlights as before. Telling the vignetted world from UI also failed on pixels with a channel at 0 (a pumpkin's stem): each channel's ratio was compared to their mean, and a 0 channel's ratio is 0. Hold the channels to one factor, the ratio of their sums, allowing a step of 8-bit rounding. Part of #1441. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/hdr.wgsl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/hdr.wgsl b/crates/horizon-client/src/hdr.wgsl index bf6c27cca..7e9dd4edf 100644 --- a/crates/horizon-client/src/hdr.wgsl +++ b/crates/horizon-client/src/hdr.wgsl @@ -30,14 +30,15 @@ const STRENGTH: f32 = 0.7; // Whether `c` still shows the world pixel `w`: the same, or darkened evenly // across its channels, as the vignette and other screen-wide tints darken it. -// The hand, HUD and text replace pixels instead, so they never pass. +// The hand, HUD and text replace pixels instead, so they never pass. The +// channels are held to one factor, the ratio of their sums, so a channel at 0 +// stays 0; a step of 8-bit rounding is allowed on each. fn shows_world(c: vec3, w: vec3) -> bool { if all(c == w) { return true; } - let k = c / max(w, vec3(1.0 / 255.0)); - let mean = (k.r + k.g + k.b) / 3.0; - return mean <= 1.01 && mean > 0.5 && all(abs(k - vec3(mean)) < vec3(0.03)); + let f = (c.r + c.g + c.b) / max(w.r + w.g + w.b, 1.0 / 255.0); + return f <= 1.01 && f > 0.5 && all(abs(c - f * w) <= 0.03 * w + 1.0 / 255.0); } @vertex fn vs_hdr(@builtin(vertex_index) i: u32) -> @builtin(position) vec4 { @@ -54,7 +55,10 @@ fn shows_world(c: vec3, w: vec3) -> bool { // The world's alpha is 0 on light-emitting blocks, the sun and the moon // (terrain.wgsl, the celestial pipeline): only those shine. if params.world > 0.5 && params.peak > 1.0 && w.a < 0.75 && shows_world(c, w.rgb) { - let y = 0.5 * (dot(light, vec3(0.2126, 0.7152, 0.0722)) + max(light.r, max(light.g, light.b))); + // Brightness of the world pixel, before the vignette darkens the frame + // toward its edges: a light source shines the same anywhere on screen. + let wl = pow(max(w.rgb, vec3(0.0)), vec3(2.2)); + let y = 0.5 * (dot(wl, vec3(0.2126, 0.7152, 0.0722)) + max(wl.r, max(wl.g, wl.b))); let lift = smoothstep(LIFT_START, LIFT_FULL, y); if lift > 0.0 { let top = max(light.r, max(light.g, light.b));