From 183bb0691d5b87e227cc614a39a177825f8a230b Mon Sep 17 00:00:00 2001 From: "Poulpe (Silver Surfer deploy)" Date: Mon, 20 Apr 2026 17:59:08 +0000 Subject: [PATCH] polish(ambience): depth-based fog/ambient darkening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Interpole en temps réel bg/ambient/fog entre palette de surface (teal lumineux y=55) et palette abyssale (bleu-noir y=-40). Fog density augmente en plongée (0.02 → 0.055) pour renforcer la sensation oppressante des grandes profondeurs. Courbe smoothstep pour transition organique. Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/ambience/UnderwaterEnvironment.gd | 111 +++++++++++++++------- 1 file changed, 78 insertions(+), 33 deletions(-) diff --git a/scripts/ambience/UnderwaterEnvironment.gd b/scripts/ambience/UnderwaterEnvironment.gd index aa4e085..6203dd4 100644 --- a/scripts/ambience/UnderwaterEnvironment.gd +++ b/scripts/ambience/UnderwaterEnvironment.gd @@ -1,29 +1,52 @@ extends WorldEnvironment +const SHALLOW_Y: float = 55.0 +const ABYSS_Y: float = -40.0 + +var _env: Environment = null +var _player: Node3D = null +var _next_player_scan: float = 0.0 + +# Reference palette at shallow depth (near surface) +var _shallow_bg: Color = Color(0.03, 0.12, 0.22) +var _shallow_ambient: Color = Color(0.2, 0.4, 0.6) +var _shallow_fog: Color = Color(0.1, 0.3, 0.5) +var _shallow_vol_fog: Color = Color(0.2, 0.5, 0.7) +var _shallow_fog_density: float = 0.02 +var _shallow_ambient_energy: float = 0.4 + +# Palette at abyssal depth +var _abyss_bg: Color = Color(0.01, 0.02, 0.05) +var _abyss_ambient: Color = Color(0.04, 0.07, 0.14) +var _abyss_fog: Color = Color(0.02, 0.04, 0.08) +var _abyss_vol_fog: Color = Color(0.05, 0.10, 0.18) +var _abyss_fog_density: float = 0.055 +var _abyss_ambient_energy: float = 0.12 + + func _ready() -> void: - var env := Environment.new() + _env = Environment.new() - env.background_mode = Environment.BG_COLOR - env.background_color = Color(0.03, 0.12, 0.22) + _env.background_mode = Environment.BG_COLOR + _env.background_color = _shallow_bg - env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR - env.ambient_light_color = Color(0.2, 0.4, 0.6) - env.ambient_light_energy = 0.4 + _env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR + _env.ambient_light_color = _shallow_ambient + _env.ambient_light_energy = _shallow_ambient_energy - env.fog_enabled = true - env.fog_light_color = Color(0.1, 0.3, 0.5) - env.fog_density = 0.02 - env.fog_aerial_perspective = 0.3 + _env.fog_enabled = true + _env.fog_light_color = _shallow_fog + _env.fog_density = _shallow_fog_density + _env.fog_aerial_perspective = 0.3 - env.volumetric_fog_enabled = true - env.volumetric_fog_density = 0.05 - env.volumetric_fog_albedo = Color(0.2, 0.5, 0.7) - env.volumetric_fog_emission = Color(0.02, 0.06, 0.1) - env.volumetric_fog_emission_energy = 0.1 - env.volumetric_fog_length = 64.0 - env.volumetric_fog_detail_spread = 2.0 + _env.volumetric_fog_enabled = true + _env.volumetric_fog_density = 0.05 + _env.volumetric_fog_albedo = _shallow_vol_fog + _env.volumetric_fog_emission = Color(0.02, 0.06, 0.1) + _env.volumetric_fog_emission_energy = 0.1 + _env.volumetric_fog_length = 64.0 + _env.volumetric_fog_detail_spread = 2.0 - # Attach custom fog shader var fog_mat := FogMaterial.new() var fog_shader := load("res://shaders/underwater_fog.gdshader") if fog_shader: @@ -34,22 +57,44 @@ func _ready() -> void: fog_volume.material = fog_mat add_child(fog_volume) - env.glow_enabled = true - env.glow_intensity = 0.5 - env.glow_bloom = 0.1 - env.glow_blend_mode = Environment.GLOW_BLEND_MODE_SOFTLIGHT + _env.glow_enabled = true + _env.glow_intensity = 0.5 + _env.glow_bloom = 0.1 + _env.glow_blend_mode = Environment.GLOW_BLEND_MODE_SOFTLIGHT - env.ssao_enabled = true - env.ssao_radius = 1.0 - env.ssao_intensity = 1.0 - env.ssao_power = 1.5 - env.ssao_detail = 0.5 + _env.ssao_enabled = true + _env.ssao_radius = 1.0 + _env.ssao_intensity = 1.0 + _env.ssao_power = 1.5 + _env.ssao_detail = 0.5 - env.tone_mapper = Environment.TONE_MAPPER_FILMIC - env.exposure = 1.0 + _env.tone_mapper = Environment.TONE_MAPPER_FILMIC + _env.exposure = 1.0 - env.adjustment_enabled = true - env.adjustment_saturation = 1.1 - env.adjustment_color_correction = null + _env.adjustment_enabled = true + _env.adjustment_saturation = 1.1 + _env.adjustment_color_correction = null - environment = env + environment = _env + + +func _process(delta: float) -> void: + _next_player_scan -= delta + if not is_instance_valid(_player) and _next_player_scan <= 0.0: + _next_player_scan = 1.0 + _player = get_tree().get_first_node_in_group("player") as Node3D + + if not is_instance_valid(_player) or _env == null: + return + + var y: float = _player.global_position.y + var t: float = clampf(inverse_lerp(SHALLOW_Y, ABYSS_Y, y), 0.0, 1.0) + # ease curve: more rapid darkening in mid-depth + var t_curved: float = smoothstep(0.0, 1.0, t) + + _env.background_color = _shallow_bg.lerp(_abyss_bg, t_curved) + _env.ambient_light_color = _shallow_ambient.lerp(_abyss_ambient, t_curved) + _env.ambient_light_energy = lerpf(_shallow_ambient_energy, _abyss_ambient_energy, t_curved) + _env.fog_light_color = _shallow_fog.lerp(_abyss_fog, t_curved) + _env.fog_density = lerpf(_shallow_fog_density, _abyss_fog_density, t_curved) + _env.volumetric_fog_albedo = _shallow_vol_fog.lerp(_abyss_vol_fog, t_curved)