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) <noreply@anthropic.com>
101 lines
3.2 KiB
GDScript
101 lines
3.2 KiB
GDScript
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:
|
|
_env = Environment.new()
|
|
|
|
_env.background_mode = Environment.BG_COLOR
|
|
_env.background_color = _shallow_bg
|
|
|
|
_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 = _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 = _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
|
|
|
|
var fog_mat := FogMaterial.new()
|
|
var fog_shader := load("res://shaders/underwater_fog.gdshader")
|
|
if fog_shader:
|
|
fog_mat.set_shader(fog_shader)
|
|
|
|
var fog_volume := FogVolume.new()
|
|
fog_volume.size = Vector3(2000.0, 300.0, 2000.0)
|
|
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.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.adjustment_enabled = true
|
|
_env.adjustment_saturation = 1.1
|
|
_env.adjustment_color_correction = null
|
|
|
|
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)
|