diff --git a/client/shaders/fog.gdshader b/client/shaders/fog.gdshader index 2590be87d..27c11df8b 100644 --- a/client/shaders/fog.gdshader +++ b/client/shaders/fog.gdshader @@ -22,10 +22,34 @@ uniform float time; // Seconds since start const vec3 UNEXPLORED_COLOR = vec3(0.071, 0.078, 0.102); // #12141a const vec3 DARK_OVERLAY = vec3(0.02, 0.02, 0.05); -// D-059 thresholds (after bilinear filtering) +// D-059 thresholds // Forward tiles = 1.0, Peripheral = 0.706 (180/255), not-visible = 0.0 const float CLEAR_THRESHOLD = 0.85; // Above this: fully clear -const float PERIPHERAL_LOW = 0.55; // Below this: transition to deep/unexplored +// Lowered from 0.55 to capture blur-extended gradient tiles in the peripheral +// branch. The 7x7 Gaussian (sigma 2.0) produces values down to ~0.08 at +// 3 tiles from the LOS boundary — together with bilinear interpolation this +// yields the 6-8 sim tile soft edge specified by D-059/D-066. +const float PERIPHERAL_LOW = 0.08; + +// D-059: Soft gradient via 7x7 Gaussian blur on visibility (sigma 2.0). +// The visibility texture is 1 texel per sim tile with discrete values +// (0 / 180 / 255). Bilinear filtering alone only smooths across ~1 tile. +// This blur spreads the LOS boundary into a 3-4 tile radius gradient; +// combined with smoothstep transitions, produces 6-8 tile soft edge. +// 49 taps from a tiny (~128x128) fully-cached texture — well under 1ms. +float sample_visibility(vec2 uv) { + vec2 t = 1.0 / map_size; + float sum = 0.0; + float weight = 0.0; + for (float dy = -3.0; dy <= 3.0; dy += 1.0) { + for (float dx = -3.0; dx <= 3.0; dx += 1.0) { + float w = exp(-(dx * dx + dy * dy) / 8.0); + sum += texture(visibility_tex, uv + vec2(dx, dy) * t).r * w; + weight += w; + } + } + return sum / weight; +} void fragment() { // Map UV (0-1 across ColorRect) to world pixels, then to tile coordinates @@ -39,15 +63,22 @@ void fragment() { if (tex_uv.x < 0.0 || tex_uv.x > 1.0 || tex_uv.y < 0.0 || tex_uv.y > 1.0) { COLOR = vec4(UNEXPLORED_COLOR, 1.0); } else { - float vis = texture(visibility_tex, tex_uv).r; + float vis_raw = texture(visibility_tex, tex_uv).r; + float vis = sample_visibility(tex_uv); float explored = texture(exploration_tex, tex_uv).r; + // Don't bleed gradient into never-explored tiles — keep them Layer 5 + if (explored < 0.01 && vis_raw < 0.01) { + vis = 0.0; + } + if (vis > PERIPHERAL_LOW) { // In or near vision cone if (vis > CLEAR_THRESHOLD) { // Layer 1: Clear — soft edge gradient + // Alpha matches Layer 2 at boundary (coverage=1.0 → 0.25) for continuity float edge = smoothstep(CLEAR_THRESHOLD, 1.0, vis); - COLOR = vec4(0.0, 0.0, 0.0, 1.0 - edge); + COLOR = vec4(DARK_OVERLAY, 0.25 * (1.0 - edge)); } else { // Layer 2: Light fog (peripheral + forward edge) // D-059: animated Perlin noise, 8-10s cycle