tron-room-demo: fog toward the background color (fade into the void)

The fog target is now COL_BG instead of the steel haze: far geometry
converges exactly onto the void color, so the deck dissolves seamlessly
into the background instead of glowing against it.

This exposed and fixed a channel bug in fogMix: the green channel
divided by 64 instead of 32 (blended at half strength). It was
invisible while the fog color's green level matched the walls', but
fading toward g=0 left far walls tinted green. fogMix is now a
weighted average (c*(32-f) + fog*f) with per-channel rounding, exact
at both ends and unbiased in either direction.
This commit is contained in:
Dejvino
2026-11-16 22:55:35 +01:00
parent 89250d7f19
commit 34384ac4d8
2 changed files with 14 additions and 13 deletions
+2 -3
View File
@@ -26,9 +26,8 @@ push, which on the device ships the 565 buffer as-is).
- `#` walls, `o` cover crates, the `+` blast door and the `T` terminal
as solid shaded boxes: backface culling, painter's-algorithm depth
sort, lambert lighting from above, bright top rims, and depth fog —
geometry fades toward a steel haze color with camera distance
(aerial perspective), so the far deck dissolves atmospherically
instead of just darkening.
geometry blends toward the background color with camera distance, so
the far deck dissolves seamlessly into the void.
- Floor tiles as lit quads with a subtle checker.
- The demo map's **network graph** as glowing pylons with teal link
lines and cyan packets traveling along the edges.
+12 -10
View File
@@ -70,11 +70,10 @@ static inline uint16_t shade565(uint16_t c, int f32) {
return (uint16_t)((r << 11) | (g << 5) | b);
}
// --- Depth fog (aerial perspective) -------------------------------------------
// Geometry fades toward a haze color with camera distance, instead of
// merely darkening: near surfaces stay crisp and saturated, the far deck
// dissolves into the haze. Integer fixed-point on the 5/6/5 channels.
static const uint16_t COL_FOG = 0x4AAD; // cool steel haze (76,88,104)
// --- Depth fog (fade into the void) -------------------------------------------
// Geometry blends toward the background color with camera distance, so the
// far deck dissolves seamlessly into the void instead of merely darkening.
// Integer fixed-point on the 5/6/5 channels.
static const float FOG_NEAR = 16.0f; // distance where fog starts
static const float FOG_FAR = 50.0f; // distance of full fog
@@ -86,15 +85,18 @@ static inline int fogAmt(float d) {
return f;
}
// Blend a native 565 color toward the fog color by a 0..32 fixed-point amount.
// Blend a native 565 color toward the background color by a 0..32
// fixed-point amount. Weighted-average form (all terms positive), so it
// is exact at both ends: f32=0 returns c, f32=32 returns COL_BG.
static inline uint16_t fogMix(uint16_t c, int f32) {
if (f32 <= 0) return c;
if (f32 > 32) f32 = 32;
int inv = 32 - f32;
int r = (c >> 11) & 31, g = (c >> 5) & 63, b = c & 31;
int fr = (COL_FOG >> 11) & 31, fg = (COL_FOG >> 5) & 63, fb = COL_FOG & 31;
r += ((fr - r) * f32 + 16) >> 5;
g += ((fg - g) * f32 + 32) >> 6;
b += ((fb - b) * f32 + 16) >> 5;
int fr = (COL_BG >> 11) & 31, fg = (COL_BG >> 5) & 63, fb = COL_BG & 31;
r = (r * inv + fr * f32 + 16) >> 5;
g = (g * inv + fg * f32 + 32) >> 6;
b = (b * inv + fb * f32 + 16) >> 5;
return (uint16_t)((r << 11) | (g << 5) | b);
}