From 968f93988334ba59b8e4b1853272c9bb6c5fdf03 Mon Sep 17 00:00:00 2001
From: pkuzic
Date: Fri, 25 Sep 2026 16:54:31 +0100
Subject: [PATCH] MONKEY (fix-sky): Enhanced/High sky mixes the Modern fog
horizon into the gradient
The integration wrapped the final gamma colour in fog_sky_horizon, whose weight
is 1 at 0 deg, so the sunset glow was erased at the horizon. Mix the Modern far
fog colour into the linear gradient before the glow and stars (review A1) and
return from the SKY_FX branch; the Classic tail keeps fog_sky_horizon.
Co-Authored-By: Claude Opus 5.5
---
crates/benilla-world/src/shaders/sky.wgsl | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/crates/benilla-world/src/shaders/sky.wgsl b/crates/benilla-world/src/shaders/sky.wgsl
index 5026dc29..bf732117 100644
--- a/crates/benilla-world/src/shaders/sky.wgsl
+++ b/crates/benilla-world/src/shaders/sky.wgsl
@@ -113,6 +113,16 @@ fn fragment(in: VertexOutput) -> @location(0) vec4 {
sky_fx::srgb_to_linear(sky.sky0.rgb),
);
var lin = sky_fx::smooth_gradient(elev, stops);
+ // MONKEY (fix-sky): the Modern fog horizon goes into the gradient, in linear light, BEFORE
+ // the glow and stars, so the fog wall meets the dome without a seam and the sunset halo is
+ // not erased at 0° (the Classic tail below applies it to `col` instead).
+ if (fog_hook::fog_is_modern(sky.mf_fog_d)) {
+ let far = fog_hook::fog_modern_colour(
+ sky.fog.rgb, dir, 1.0e9, sky.mf_fog_b, sky.mf_fog_c, sky.mf_fog_d,
+ );
+ let w = 1.0 - smoothstep(0.0, 0.26179939, asin(clamp(dir.y, -1.0, 1.0)));
+ lin = mix(lin, sky_fx::srgb_to_linear(far), w);
+ }
// Sun glow: a halo tinted by the sun and fog colours, faded at night and under cloud on the
// CPU; below the horizon it thins out over the fog band.
if (sky.fx.w > 0.0) {
@@ -133,13 +143,14 @@ fn fragment(in: VertexOutput) -> @location(0) vec4 {
lin += (stars * 0.85 + milky) * night;
}
let out = sky_fx::linear_to_srgb(lin) + vec3(sky_fx::dither_tri(in.position.xy));
- col = clamp(out, vec3(0.0), vec3(1.0));
+ // The horizon is already in: skip the Classic-path tail.
+ return vec4(clamp(out, vec3(0.0), vec3(1.0)), 1.0);
}
#endif
// Raw gamma out: the reference draws the sky as raw DBC bytes, sRGB off (`0x6d4940`).
- // MONKEY (fog): Modern eases the low band into the world's far fog colour after either the
- // Classic or Enhanced/High gradient path; Classic returns `col` unchanged.
+ // MONKEY (fog): Modern eases the low band into the world's far fog colour after the Classic
+ // gradient (Enhanced/High mixes it in above); Classic fog returns `col` unchanged.
let rgb = fog_hook::fog_sky_horizon(
col, sky.fog.rgb, dir, sky.mf_fog_b, sky.mf_fog_c, sky.mf_fog_d,
);