Godot 4.6 OpenGL3 compatibility mode does not support 'return' in fragment(). The early returns on lines 68 and 82 caused silent shader compilation failure, making the fog overlay render as a no-op — the root cause of the Sprint 22 fog regression. Restructured to if/else-if/else chain preserving identical logic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
118 lines
5.3 KiB
Plaintext
118 lines
5.3 KiB
Plaintext
shader_type canvas_item;
|
|
|
|
// D-059/D-015: 3-state fog shader (simplified from 5-layer by #569).
|
|
// State 1: Clear (forward cone) — transparent, soft Gaussian gradient edge (3-4 tile radius)
|
|
// State 2: Explored (out of cone) — light fog overlay, alpha 0.25-0.35, zone temperature tint,
|
|
// 8-10s Perlin breathe. Art and information preserved, just "not fresh" (D-015).
|
|
// State 3: Unexplored — solid near-black #12141a
|
|
// D-033: Entity colors are NOT affected — they render above the fog overlay (z-layer 5).
|
|
// D-046: Zone temperature tint from zone_tint_tex — warm=bar, cool=hub, neutral=corridor.
|
|
// D-077: zone_tint_tex populated per-tile from server zone_id via fog_state.gd.
|
|
|
|
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; // nearest: zones have hard boundaries (D-073)
|
|
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
|
|
uniform bool debug_exploration = false; // When true, render raw exploration texture
|
|
|
|
const vec3 UNEXPLORED_COLOR = vec3(0.071, 0.078, 0.102); // #12141a
|
|
|
|
// Soft gradient via 7x7 Gaussian blur on visibility (sigma 2.0).
|
|
// Spreads the cone boundary into a 3-4 tile radius gradient — no hard tile-stepped edges.
|
|
float sample_visibility(vec2 uv) {
|
|
vec2 t = 2.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;
|
|
}
|
|
|
|
// Soft gradient on exploration boundary (5x5, sigma 1.5).
|
|
// Prevents hard tile-stepped staircase at explored/unexplored edge.
|
|
float sample_exploration(vec2 uv) {
|
|
vec2 t = 1.0 / map_size;
|
|
float sum = 0.0;
|
|
float weight = 0.0;
|
|
for (float dy = -2.0; dy <= 2.0; dy += 1.0) {
|
|
for (float dx = -2.0; dx <= 2.0; dx += 1.0) {
|
|
float w = exp(-(dx * dx + dy * dy) / 4.5);
|
|
vec2 sample_uv = clamp(uv + vec2(dx, dy) * t, vec2(0.0), vec2(1.0));
|
|
sum += texture(exploration_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
|
|
// Note: no early return — fragment() in OpenGL3 compat doesn't support return.
|
|
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);
|
|
|
|
// Debug mode: render raw exploration texture (bypass fog rendering).
|
|
// Green = EXP_VISIBLE (255), blue = EXP_EXPLORED (128), red = EXP_UNEXPLORED (0).
|
|
} else if (debug_exploration) {
|
|
float explored_dbg = texture(exploration_tex, tex_uv).r;
|
|
if (explored_dbg > 0.9) {
|
|
COLOR = vec4(0.0, explored_dbg, 0.0, 0.8); // Green: currently visible
|
|
} else if (explored_dbg > 0.1) {
|
|
COLOR = vec4(0.0, 0.0, explored_dbg * 2.0, 0.8); // Blue: explored
|
|
} else {
|
|
COLOR = vec4(0.5, 0.0, 0.0, 0.8); // Red: unexplored
|
|
}
|
|
|
|
} else {
|
|
float vis_raw = texture(visibility_tex, tex_uv).r;
|
|
float vis = sample_visibility(tex_uv);
|
|
float explored_raw = texture(exploration_tex, tex_uv).r;
|
|
float explored = sample_exploration(tex_uv);
|
|
|
|
// Prevent gradient bleed into never-explored tiles (use raw, unblurred value)
|
|
if (explored_raw < 0.01 && vis_raw < 0.01) {
|
|
vis = 0.0;
|
|
}
|
|
|
|
if (explored < 0.01 && vis < 0.01) {
|
|
// Unexplored: solid near-black — information zero
|
|
COLOR = vec4(UNEXPLORED_COLOR, 1.0);
|
|
} else {
|
|
// Fog noise — 8-10s breathe cycle, ±0.05 symmetric around baseline
|
|
float noise_val = texture(noise_tex, tile * 0.03 + vec2(time * 0.11, time * 0.07)).r;
|
|
float fog_alpha = 0.30 + (noise_val * 2.0 - 1.0) * 0.05; // 0.25-0.35
|
|
|
|
// Zone temperature tint (D-046/D-077): subtle warm/cool/neutral per zone
|
|
vec3 zone_tint = texture(zone_tint_tex, tex_uv).rgb;
|
|
|
|
// Clarity ramp: transparent inside cone, light fog at edges and beyond
|
|
float clarity = smoothstep(0.0, 0.85, vis);
|
|
float alpha = mix(fog_alpha, 0.0, clarity);
|
|
vec3 color = mix(zone_tint, vec3(0.0), clarity);
|
|
|
|
// Soft edge between explored and unexplored (blurred to avoid staircase)
|
|
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);
|
|
}
|
|
}
|
|
}
|