Merge remote-tracking branch 'origin/visual'
# Conflicts: # CHANGELOG.md # client/scripts/autoloads/fog_state.gd # client/shaders/fog.gdshader
This commit is contained in:
@@ -8,12 +8,29 @@ extends Node
|
||||
# Used by fog shader to distinguish visual treatment per tile.
|
||||
# Test assertions reference these: assert_that(byte).is_equal(FogState.VIS_FORWARD)
|
||||
const VIS_HIDDEN: int = 0 # Not in LOS — fully fogged
|
||||
const VIS_PERIPHERAL: int = 180 # DEPRECATED: peripheral sector removed in Sprint 22 (#569). Retained — tests still reference it.
|
||||
const VIS_FORWARD: int = 255 # In LOS, forward sector — clear vision
|
||||
|
||||
const EXP_UNEXPLORED: int = 0 # Never seen — total darkness
|
||||
const EXP_EXPLORED: int = 128 # Previously seen, now out of LOS — deep fog
|
||||
const EXP_VISIBLE: int = 255 # Currently in LOS — clear (written each frame)
|
||||
|
||||
# Zone temperature tints (D-059 + D-046, Sprint 22) — keyed by zone_id string from server.
|
||||
# Matches audio_manager.gd ZONE_ASSETS zone_id strings for consistent zone semantics.
|
||||
# Low saturation is intentional (D-046): tints are subtle — distinguishable as warm/cool/neutral
|
||||
# in side-by-side comparison, not garish. The "Hopper test" validates this.
|
||||
# Colors are dark tints used as the fog overlay in the deep fog zone:
|
||||
# hub/workplace: #1a1f2e (cool blue-dark — terminal, institutional)
|
||||
# bar: #2a1f15 (warm amber-dark — social, inhabited)
|
||||
# corridor: #1a1a1a (neutral dark — transitional, maintenance)
|
||||
const ZONE_TINTS: Dictionary = {
|
||||
"hub": Color(0.102, 0.122, 0.180), # #1a1f2e — cool blue-dark
|
||||
"workplace": Color(0.102, 0.122, 0.180), # same as hub
|
||||
"bar": Color(0.165, 0.122, 0.082), # #2a1f15 — warm amber-dark
|
||||
"corridor": Color(0.102, 0.102, 0.102), # #1a1a1a — neutral dark
|
||||
}
|
||||
const ZONE_TINT_DEFAULT: Color = Color(0.102, 0.102, 0.102) # #1a1a1a neutral
|
||||
|
||||
var map_bounds: Rect2i = Rect2i(0, 0, 1, 1)
|
||||
var visibility_texture: ImageTexture
|
||||
var exploration_texture: ImageTexture
|
||||
@@ -24,6 +41,8 @@ var _exp_bytes: PackedByteArray
|
||||
var _vis_image: Image
|
||||
var _exp_image: Image
|
||||
var _tint_image: Image
|
||||
# Zone tint stored as 3-channel RGB bytes (R, G, B per pixel) for preservation across resizes
|
||||
var _tint_bytes: PackedByteArray
|
||||
var _width: int = 1
|
||||
var _height: int = 1
|
||||
var _prev_visible: Dictionary = {} # Tiles visible last frame (for incremental decay)
|
||||
@@ -41,6 +60,7 @@ func _ready() -> void:
|
||||
func _resize(bounds: Rect2i) -> void:
|
||||
var old_bounds := map_bounds
|
||||
var old_exp := _exp_bytes
|
||||
var old_tint := _tint_bytes # empty on first call (_ready); guard at line 104 skips copy
|
||||
var old_w := _width
|
||||
var old_h := _height
|
||||
|
||||
@@ -76,9 +96,35 @@ func _resize(bounds: Rect2i) -> void:
|
||||
_exp_image = Image.create_from_data(_width, _height, false, Image.FORMAT_R8, _exp_bytes)
|
||||
exploration_texture = ImageTexture.create_from_image(_exp_image)
|
||||
|
||||
# Zone tint — neutral dark for Sprint 6 (zone metadata deferred)
|
||||
_tint_image = Image.create(_width, _height, false, Image.FORMAT_RGB8)
|
||||
_tint_image.fill(Color(0.05, 0.05, 0.08))
|
||||
# Zone tint — 3 bytes per pixel (RGB), default neutral dark
|
||||
var tint_sz := sz * 3
|
||||
_tint_bytes = PackedByteArray()
|
||||
_tint_bytes.resize(tint_sz)
|
||||
var default_r := int(ZONE_TINT_DEFAULT.r * 255.0)
|
||||
var default_g := int(ZONE_TINT_DEFAULT.g * 255.0)
|
||||
var default_b := int(ZONE_TINT_DEFAULT.b * 255.0)
|
||||
for i in range(sz):
|
||||
_tint_bytes[i * 3 + 0] = default_r
|
||||
_tint_bytes[i * 3 + 1] = default_g
|
||||
_tint_bytes[i * 3 + 2] = default_b
|
||||
# Preserve zone tint data from old bounds (zone tints are stable — tile zone never changes)
|
||||
if old_tint.size() > 0 and old_w > 0 and old_h > 0:
|
||||
var dx: int = old_bounds.position.x - bounds.position.x
|
||||
var dy: int = old_bounds.position.y - bounds.position.y
|
||||
for oy in range(old_h):
|
||||
var ny: int = oy + dy
|
||||
if ny < 0 or ny >= _height:
|
||||
continue
|
||||
for ox in range(old_w):
|
||||
var nx: int = ox + dx
|
||||
if nx < 0 or nx >= _width:
|
||||
continue
|
||||
var old_idx := (oy * old_w + ox) * 3
|
||||
var new_idx := (ny * _width + nx) * 3
|
||||
_tint_bytes[new_idx + 0] = old_tint[old_idx + 0]
|
||||
_tint_bytes[new_idx + 1] = old_tint[old_idx + 1]
|
||||
_tint_bytes[new_idx + 2] = old_tint[old_idx + 2]
|
||||
_tint_image = Image.create_from_data(_width, _height, false, Image.FORMAT_RGB8, _tint_bytes)
|
||||
zone_tint_texture = ImageTexture.create_from_image(_tint_image)
|
||||
|
||||
_prev_visible.clear()
|
||||
@@ -132,6 +178,35 @@ func update_from_state() -> void:
|
||||
_exp_image.set_data(_width, _height, false, Image.FORMAT_R8, _exp_bytes)
|
||||
exploration_texture.update(_exp_image)
|
||||
|
||||
# 3. Zone tint: write zone temperature color for currently visible tiles.
|
||||
# Zone data is stable (tile zone never changes) so we only write on first sight.
|
||||
# Data persists in _tint_bytes across frames and across resizes.
|
||||
var tint_dirty := false
|
||||
for tile in tiles:
|
||||
if not tile is Dictionary or not tile.has("x") or not tile.has("y"):
|
||||
continue
|
||||
var zone_id: String = str(tile.get("zone_id", ""))
|
||||
if zone_id.is_empty():
|
||||
continue
|
||||
var tint_color: Color = ZONE_TINTS.get(zone_id, ZONE_TINT_DEFAULT)
|
||||
var px: int = int(tile.x) - ox
|
||||
var py: int = int(tile.y) - oy
|
||||
if px < 0 or py < 0 or px >= _width or py >= _height:
|
||||
continue
|
||||
var tint_idx := (py * _width + px) * 3
|
||||
var new_r := int(tint_color.r * 255.0)
|
||||
var new_g := int(tint_color.g * 255.0)
|
||||
var new_b := int(tint_color.b * 255.0)
|
||||
# Only update if different from current (avoid spurious texture uploads)
|
||||
if _tint_bytes[tint_idx] != new_r or _tint_bytes[tint_idx + 1] != new_g or _tint_bytes[tint_idx + 2] != new_b:
|
||||
_tint_bytes[tint_idx + 0] = new_r
|
||||
_tint_bytes[tint_idx + 1] = new_g
|
||||
_tint_bytes[tint_idx + 2] = new_b
|
||||
tint_dirty = true
|
||||
if tint_dirty:
|
||||
_tint_image.set_data(_width, _height, false, Image.FORMAT_RGB8, _tint_bytes)
|
||||
zone_tint_texture.update(_tint_image)
|
||||
|
||||
# Shallow copy — correct for Dictionary<Vector2i, bool/String> values
|
||||
_prev_visible = positions.duplicate()
|
||||
|
||||
|
||||
+61
-40
@@ -1,13 +1,18 @@
|
||||
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 (~25-30%), art fully preserved
|
||||
// Layer 3: Unexplored — solid near-black #12141a
|
||||
// D-059: 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, EXP_EXPLORED) — two sub-zones by vis proximity:
|
||||
// a) Light fog (near cone gradient): alpha 0.25-0.35, neutral dark, 8-10s breathe
|
||||
// b) Deep fog (far from cone, vis≈0): alpha 0.55-0.70, zone temperature tint, 15-20s breathe
|
||||
// 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_nearest, repeat_disable;
|
||||
uniform sampler2D zone_tint_tex : filter_nearest, 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)
|
||||
@@ -18,12 +23,10 @@ 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
|
||||
const vec3 FOG_OVERLAY_COLOR = vec3(0.06, 0.07, 0.12); // Dark blue-grey fog tint
|
||||
const vec3 DARK_OVERLAY = vec3(0.02, 0.02, 0.05); // neutral dark (light fog zone)
|
||||
|
||||
// D-066: 6-8 sim tile soft gradient at cone boundary.
|
||||
// 7x7 Gaussian kernel sampling at 2-texel intervals spreads across ±6 tiles.
|
||||
// Effective sigma = 4 tiles in world space (sigma_kernel=2.0 * step=2.0).
|
||||
// At 2-sigma (8 tiles): weight drops to 0.14, giving ~6-8 tile visible gradient.
|
||||
// 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;
|
||||
@@ -50,12 +53,10 @@ void fragment() {
|
||||
return;
|
||||
}
|
||||
|
||||
float vis = sample_visibility(tex_uv);
|
||||
float explored = texture(exploration_tex, tex_uv).r;
|
||||
|
||||
// Debug mode: render raw exploration texture (bypass fog rendering).
|
||||
// Green = EXP_VISIBLE (255), blue = EXP_EXPLORED (128), red = EXP_UNEXPLORED (0).
|
||||
if (debug_exploration) {
|
||||
float explored = texture(exploration_tex, tex_uv).r;
|
||||
if (explored > 0.9) {
|
||||
COLOR = vec4(0.0, explored, 0.0, 0.8); // Green: currently visible
|
||||
} else if (explored > 0.1) {
|
||||
@@ -66,36 +67,56 @@ void fragment() {
|
||||
return;
|
||||
}
|
||||
|
||||
// D-066: 6-8 sim tile gradient at the cone boundary.
|
||||
// smoothstep(0.02, 0.95, vis) maps the Gaussian-blurred visibility into a
|
||||
// smooth clarity ramp spanning the full blur radius — no tile-stepping.
|
||||
float clarity = smoothstep(0.02, 0.95, vis);
|
||||
float vis_raw = texture(visibility_tex, tex_uv).r;
|
||||
float vis = sample_visibility(tex_uv);
|
||||
float explored = texture(exploration_tex, tex_uv).r;
|
||||
|
||||
if (explored < 0.01) {
|
||||
// Unexplored: smooth fade from transparent (inside cone) to solid black (beyond).
|
||||
// The Gaussian vis gradient drives alpha — same ramp as explored fog — so the
|
||||
// cone edge looks seamless regardless of whether adjacent tiles are explored.
|
||||
// World art is NOT preserved in this region: alpha approaches 1.0 outside the cone.
|
||||
COLOR = vec4(UNEXPLORED_COLOR, 1.0 - clarity);
|
||||
return;
|
||||
// Prevent gradient bleed into never-explored tiles
|
||||
if (explored < 0.01 && vis_raw < 0.01) {
|
||||
vis = 0.0;
|
||||
}
|
||||
|
||||
// Explored fog: light overlay preserving all art and information (D-059).
|
||||
// fog_alpha ~0.27-0.31 -> world appears at ~70% brightness with blue-grey tint.
|
||||
// 8-10s Perlin noise adds atmosphere without obscuring content.
|
||||
float noise_val = texture(noise_tex, tile * 0.03 + vec2(time * 0.11, time * 0.07)).r;
|
||||
float fog_alpha = 0.27 + noise_val * 0.04;
|
||||
if (explored < 0.01 && vis < 0.01) {
|
||||
// Unexplored: solid near-black — information zero
|
||||
COLOR = vec4(UNEXPLORED_COLOR, 1.0);
|
||||
} else {
|
||||
// Light fog noise — fast cycle (~9s), ±0.05 breathing
|
||||
float noise_fast = texture(noise_tex, tile * 0.03 + vec2(time * 0.11, time * 0.07)).r;
|
||||
// Deep fog noise — slow cycle (~20s), ±0.075 breathing (more pronounced)
|
||||
float noise_slow = texture(noise_tex, tile * 0.02 + vec2(time * 0.05, time * 0.035)).r;
|
||||
|
||||
// Blend from fog (clarity=0, out of cone) to clear (clarity=1, in cone)
|
||||
float alpha = mix(fog_alpha, 0.0, clarity);
|
||||
vec3 color = mix(FOG_OVERLAY_COLOR, vec3(0.0), clarity);
|
||||
// Light fog: alpha 0.25-0.35 (centered at 0.30, ±0.05 breathe)
|
||||
// Noise remapped to [-1,+1] for symmetric breathing around baseline.
|
||||
float light_fog_alpha = 0.30 + (noise_fast * 2.0 - 1.0) * 0.05;
|
||||
|
||||
// Hard step at the explored/unexplored tile boundary.
|
||||
// exploration_tex uses filter_nearest: explored is exactly 0.0, ~0.5, or 1.0.
|
||||
// smoothstep maps these to 0.0 or 1.0 — no sub-tile blending.
|
||||
float exp_fade = smoothstep(0.0, 0.2, explored);
|
||||
alpha = mix(1.0, alpha, exp_fade);
|
||||
color = mix(UNEXPLORED_COLOR, color, exp_fade);
|
||||
// Deep fog: alpha 0.55-0.70 (centered at 0.625, ±0.075 breathe)
|
||||
float deep_fog_alpha = 0.625 + (noise_slow * 2.0 - 1.0) * 0.075;
|
||||
|
||||
COLOR = vec4(color, alpha);
|
||||
// Blend deep <-> light fog by proximity to cone:
|
||||
// vis=0 (far from cone) → deep_factor=1 → deep fog
|
||||
// vis=0.3 (cone gradient) → deep_factor=0 → light fog
|
||||
// vis=0.85+ (inside cone) → clarity=1 → transparent (clear)
|
||||
float deep_factor = 1.0 - smoothstep(0.0, 0.30, vis);
|
||||
float fog_alpha = mix(light_fog_alpha, deep_fog_alpha, deep_factor);
|
||||
|
||||
// Zone temperature tint (D-059/D-046/D-077):
|
||||
// Deep fog color uses zone_tint_tex; light fog uses neutral DARK_OVERLAY.
|
||||
// zone_tint_tex is populated per-tile from server zone_id via fog_state.gd.
|
||||
vec3 zone_tint = texture(zone_tint_tex, tex_uv).rgb;
|
||||
|
||||
// Clarity ramp: transparent inside cone, fogged at edges and beyond
|
||||
float clarity = smoothstep(0.0, 0.85, vis);
|
||||
float alpha = mix(fog_alpha, 0.0, clarity);
|
||||
|
||||
// Color: deep fog → zone temperature tint; light fog → neutral dark overlay
|
||||
vec3 fog_color = mix(DARK_OVERLAY, zone_tint, deep_factor);
|
||||
vec3 color = mix(fog_color, 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user