shader_type canvas_item; // D-059: 3-layer fog shader. Composites over world content. // Layer 1: Clear (forward cone) — transparent, soft gradient edge // Layer 2: Explored fog — light overlay indicating "not fresh", art preserved // Layer 3: Unexplored — solid near-black #12141a uniform sampler2D visibility_tex : filter_linear, repeat_disable; uniform sampler2D exploration_tex : filter_linear, repeat_disable; uniform sampler2D zone_tint_tex : filter_nearest, repeat_disable; uniform sampler2D noise_tex : filter_linear, repeat_enable; uniform vec2 rect_pos; // World-space position of the ColorRect (pixels) uniform vec2 rect_sz; // World-space size of the ColorRect (pixels) uniform vec2 map_offset; // map_bounds.position (tiles) uniform vec2 map_size; // map_bounds.size (tiles) uniform float tile_size; // Pixels per sim tile 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); // Soft gradient via 7x7 Gaussian blur on visibility (sigma 2.0). // Spreads the cone boundary into a 3-4 tile radius gradient for soft edges. 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); vec2 sample_uv = clamp(uv + vec2(dx, dy) * t, vec2(0.0), vec2(1.0)); sum += texture(visibility_tex, sample_uv).r * w; weight += w; } } return sum / weight; } void fragment() { vec2 world_px = rect_pos + UV * rect_sz; vec2 tile = world_px / tile_size; vec2 tex_uv = (tile - map_offset) / map_size; // Outside known map -> unexplored 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_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 if (explored < 0.01 && vis_raw < 0.01) { vis = 0.0; } if (explored < 0.01 && vis < 0.01) { // Unexplored: solid near-black COLOR = vec4(UNEXPLORED_COLOR, 1.0); } else { // Continuous blend: clear vision (vis=1) -> light fog (vis=0). // The Gaussian blur creates a smooth 3-4 tile soft gradient // at the cone edge — no hard boundary. // Light fog: subtle animated overlay, preserves all art/info float noise_val = texture(noise_tex, tile * 0.03 + vec2(time * 0.11, time * 0.07)).r; float fog_alpha = 0.28 + noise_val * 0.04; // Clarity ramp from the blurred visibility float clarity = smoothstep(0.0, 0.85, vis); float alpha = mix(fog_alpha, 0.0, clarity); vec3 color = mix(DARK_OVERLAY, vec3(0.0), clarity); // Soft edge between explored and unexplored float exp_fade = smoothstep(0.0, 0.3, explored); alpha = mix(1.0, alpha, exp_fade); color = mix(UNEXPLORED_COLOR, color, exp_fade); COLOR = vec4(color, alpha); } } }