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:
@@ -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
|
- `#` walls, `o` cover crates, the `+` blast door and the `T` terminal
|
||||||
as solid shaded boxes: backface culling, painter's-algorithm depth
|
as solid shaded boxes: backface culling, painter's-algorithm depth
|
||||||
sort, lambert lighting from above, bright top rims, and depth fog —
|
sort, lambert lighting from above, bright top rims, and depth fog —
|
||||||
geometry fades toward a steel haze color with camera distance
|
geometry blends toward the background color with camera distance, so
|
||||||
(aerial perspective), so the far deck dissolves atmospherically
|
the far deck dissolves seamlessly into the void.
|
||||||
instead of just darkening.
|
|
||||||
- Floor tiles as lit quads with a subtle checker.
|
- Floor tiles as lit quads with a subtle checker.
|
||||||
- The demo map's **network graph** as glowing pylons with teal link
|
- The demo map's **network graph** as glowing pylons with teal link
|
||||||
lines and cyan packets traveling along the edges.
|
lines and cyan packets traveling along the edges.
|
||||||
|
|||||||
@@ -70,11 +70,10 @@ static inline uint16_t shade565(uint16_t c, int f32) {
|
|||||||
return (uint16_t)((r << 11) | (g << 5) | b);
|
return (uint16_t)((r << 11) | (g << 5) | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Depth fog (aerial perspective) -------------------------------------------
|
// --- Depth fog (fade into the void) -------------------------------------------
|
||||||
// Geometry fades toward a haze color with camera distance, instead of
|
// Geometry blends toward the background color with camera distance, so the
|
||||||
// merely darkening: near surfaces stay crisp and saturated, the far deck
|
// far deck dissolves seamlessly into the void instead of merely darkening.
|
||||||
// dissolves into the haze. Integer fixed-point on the 5/6/5 channels.
|
// Integer fixed-point on the 5/6/5 channels.
|
||||||
static const uint16_t COL_FOG = 0x4AAD; // cool steel haze (76,88,104)
|
|
||||||
static const float FOG_NEAR = 16.0f; // distance where fog starts
|
static const float FOG_NEAR = 16.0f; // distance where fog starts
|
||||||
static const float FOG_FAR = 50.0f; // distance of full fog
|
static const float FOG_FAR = 50.0f; // distance of full fog
|
||||||
|
|
||||||
@@ -86,15 +85,18 @@ static inline int fogAmt(float d) {
|
|||||||
return f;
|
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) {
|
static inline uint16_t fogMix(uint16_t c, int f32) {
|
||||||
if (f32 <= 0) return c;
|
if (f32 <= 0) return c;
|
||||||
if (f32 > 32) f32 = 32;
|
if (f32 > 32) f32 = 32;
|
||||||
|
int inv = 32 - f32;
|
||||||
int r = (c >> 11) & 31, g = (c >> 5) & 63, b = c & 31;
|
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;
|
int fr = (COL_BG >> 11) & 31, fg = (COL_BG >> 5) & 63, fb = COL_BG & 31;
|
||||||
r += ((fr - r) * f32 + 16) >> 5;
|
r = (r * inv + fr * f32 + 16) >> 5;
|
||||||
g += ((fg - g) * f32 + 32) >> 6;
|
g = (g * inv + fg * f32 + 32) >> 6;
|
||||||
b += ((fb - b) * f32 + 16) >> 5;
|
b = (b * inv + fb * f32 + 16) >> 5;
|
||||||
return (uint16_t)((r << 11) | (g << 5) | b);
|
return (uint16_t)((r << 11) | (g << 5) | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user