Blend foggy ocean and sky horizons

This commit is contained in:
Alexander Sellite 2026-08-03 15:44:49 -04:00
parent 004324458d
commit de1df5ea21
4 changed files with 56 additions and 2 deletions

View file

@ -4,6 +4,7 @@ uniform vec4 sky_top_color : source_color = vec4(0.204, 0.498, 0.643, 1.0);
uniform vec4 sky_horizon_color : source_color = vec4(0.663, 0.843, 0.847, 1.0); uniform vec4 sky_horizon_color : source_color = vec4(0.663, 0.843, 0.847, 1.0);
uniform vec4 ground_bottom_color : source_color = vec4(0.157, 0.361, 0.439, 1.0); uniform vec4 ground_bottom_color : source_color = vec4(0.157, 0.361, 0.439, 1.0);
uniform vec4 ground_horizon_color : source_color = vec4(0.549, 0.749, 0.765, 1.0); uniform vec4 ground_horizon_color : source_color = vec4(0.549, 0.749, 0.765, 1.0);
uniform float horizon_blend_width : hint_range(0.005, 0.15, 0.005) = 0.01;
uniform vec3 sun_direction = vec3(0.0, 1.0, 0.0); uniform vec3 sun_direction = vec3(0.0, 1.0, 0.0);
uniform vec4 sun_color : source_color = vec4(1.0, 0.86, 0.46, 1.0); uniform vec4 sun_color : source_color = vec4(1.0, 0.86, 0.46, 1.0);
@ -39,7 +40,11 @@ void sky() {
vec3 base_color = mix( vec3 base_color = mix(
ground_color, ground_color,
sky_color, sky_color,
smoothstep(-0.01, 0.01, view_direction.y) smoothstep(
-horizon_blend_width,
horizon_blend_width,
view_direction.y
)
); );
float alignment = dot(view_direction, normalize(sun_direction)); float alignment = dot(view_direction, normalize(sun_direction));

View file

@ -35,6 +35,10 @@ uniform float open_water_drift_strength : hint_range(0.0, 0.08, 0.001) = 0.045;
uniform float distant_alpha_start : hint_range(10.0, 2000.0, 1.0) = 260.0; uniform float distant_alpha_start : hint_range(10.0, 2000.0, 1.0) = 260.0;
uniform float distant_alpha_end : hint_range(20.0, 5000.0, 1.0) = 1400.0; uniform float distant_alpha_end : hint_range(20.0, 5000.0, 1.0) = 1400.0;
uniform vec4 distant_fog_color : source_color = vec4(0.549, 0.749, 0.765, 1.0);
uniform float distant_fog_begin : hint_range(0.0, 2000.0, 1.0) = 42.0;
uniform float distant_fog_end : hint_range(1.0, 5000.0, 1.0) = 170.0;
uniform float distant_fog_strength : hint_range(0.0, 1.0, 0.01) = 0.18;
varying vec3 world_position; varying vec3 world_position;
varying float surface_view_depth; varying float surface_view_depth;
@ -233,6 +237,15 @@ void fragment() {
water_color = mix(water_color, deep_color.rgb, distant_mix * 0.72); water_color = mix(water_color, deep_color.rgb, distant_mix * 0.72);
water_alpha = mix(water_alpha, 0.96, distant_mix); water_alpha = mix(water_alpha, 0.96, distant_mix);
float fog_distance_mix = smoothstep(
distant_fog_begin,
max(distant_fog_end, distant_fog_begin + 1.0),
surface_view_depth
);
float water_fog_mix = fog_distance_mix * distant_fog_strength;
water_color = mix(water_color, distant_fog_color.rgb, water_fog_mix);
water_alpha = mix(water_alpha, 0.96, water_fog_mix);
ALBEDO = water_color; ALBEDO = water_color;
ALPHA = clamp(water_alpha, 0.1, 0.96); ALPHA = clamp(water_alpha, 0.1, 0.96);
METALLIC = 0.0; METALLIC = 0.0;

View file

@ -32,3 +32,7 @@ shader_parameter/open_water_drift_speed = Vector2(0.01, -0.007)
shader_parameter/open_water_drift_strength = 0.045 shader_parameter/open_water_drift_strength = 0.045
shader_parameter/distant_alpha_start = 260.0 shader_parameter/distant_alpha_start = 260.0
shader_parameter/distant_alpha_end = 1400.0 shader_parameter/distant_alpha_end = 1400.0
shader_parameter/distant_fog_color = Color(0.54902, 0.74902, 0.764706, 1)
shader_parameter/distant_fog_begin = 42.0
shader_parameter/distant_fog_end = 170.0
shader_parameter/distant_fog_strength = 0.18

View file

@ -9,6 +9,9 @@ const RAIN_PARTICLE_AMOUNT: int = 560
const RAIN_VELOCITY_MIN: float = 16.0 const RAIN_VELOCITY_MIN: float = 16.0
const RAIN_VELOCITY_MAX: float = 20.0 const RAIN_VELOCITY_MAX: float = 20.0
const RAIN_DROP_SIZE := Vector3(0.014, 0.34, 0.014) const RAIN_DROP_SIZE := Vector3(0.014, 0.34, 0.014)
const SALT_WATER_MATERIAL: ShaderMaterial = preload(
"res://world/materials/stylized_water.tres"
)
const DAY_SKY_TOP := Color(0.204, 0.498, 0.643) const DAY_SKY_TOP := Color(0.204, 0.498, 0.643)
const DAY_SKY_HORIZON := Color(0.663, 0.843, 0.847) const DAY_SKY_HORIZON := Color(0.663, 0.843, 0.847)
@ -232,7 +235,14 @@ func _apply_time(time_hours: float) -> void:
) )
_sky_material.set_shader_parameter( _sky_material.set_shader_parameter(
"ground_horizon_color", "ground_horizon_color",
ground_horizon.lerp(weather_tint, tint_strength * 0.76), ground_horizon.lerp(
weather_tint,
tint_strength * _weather_value(0.76, 0.82, 0.90, 1.0),
),
)
_sky_material.set_shader_parameter(
"horizon_blend_width",
_weather_value(0.01, 0.025, 0.035, 0.08),
) )
_environment.background_energy_multiplier = ( _environment.background_energy_multiplier = (
lerpf(0.52, 0.85, daylight) lerpf(0.52, 0.85, daylight)
@ -267,6 +277,7 @@ func _apply_time(time_hours: float) -> void:
_environment.fog_depth_end = _weather_value( _environment.fog_depth_end = _weather_value(
170.0, 140.0, 95.0, 42.0 170.0, 140.0, 95.0, 42.0
) )
_apply_water_haze(weather_tint)
_environment.adjustment_brightness = ( _environment.adjustment_brightness = (
lerpf(0.93, 0.98, daylight) lerpf(0.93, 0.98, daylight)
* _weather_value(1.0, 0.97, 0.92, 0.96) * _weather_value(1.0, 0.97, 0.92, 0.96)
@ -308,6 +319,27 @@ func _apply_time(time_hours: float) -> void:
_update_rain_amount() _update_rain_amount()
func _apply_water_haze(weather_tint: Color) -> void:
if SALT_WATER_MATERIAL == null:
return
SALT_WATER_MATERIAL.set_shader_parameter(
"distant_fog_color",
_environment.fog_light_color.lerp(weather_tint, 0.18),
)
SALT_WATER_MATERIAL.set_shader_parameter(
"distant_fog_begin",
_environment.fog_depth_begin,
)
SALT_WATER_MATERIAL.set_shader_parameter(
"distant_fog_end",
_environment.fog_depth_end,
)
SALT_WATER_MATERIAL.set_shader_parameter(
"distant_fog_strength",
_weather_value(0.18, 0.34, 0.52, 0.74),
)
func _on_weather_changed( func _on_weather_changed(
weather: WorldWeatherService.Weather, weather: WorldWeatherService.Weather,
_seconds_remaining: float, _seconds_remaining: float,