A6: Sea, sky and weather

Weather.at(tide, tick) derives the weather from the tide's schedule
alone, so every client sees the same sky with nothing new on the wire:
the storm builds from calm at the first tide to a gale at sudden death,
and the light runs from mid-afternoon to dusk at the time limit.
WeatherView applies it each sync to the sky, sun, fog, ambient light,
the sea's roughness and rain around the camera (CPUParticles3D, for
both renderers). Under water the view closes into SEA_MURK, the rain
stops and the surface is a rippled ceiling seen from below.

The sea shader darkens open water and adds chop and whitecaps with the
storm, and keeps a breathing foam band at the waterline with a fainter
line beyond. In the Compatibility renderer, whose depth texture the
shader can't read (the sea came out all foam), water depth comes from
a texture of the terrain's heights instead. Sea colours move into
Palette; the rain and wind beds follow the weather.

Tests: test_weather (7). make check passes (611 tests). Captures:
make sea-captures (every tide phase, calm beach, the last land in the
gale, under water, and three in the Compatibility renderer).

Closes #46

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 18:05:42 -05:00
co-authored by Claude Opus 5.5
parent a282ca8e40
commit a4e81479bb
29 changed files with 703 additions and 22 deletions
+106
View File
@@ -0,0 +1,106 @@
## Capture scenario for the sea, sky and weather (A6), on seed 2's island in the real
## MatchView, with the tide set as the server would have it:
##
## - tide_0: the first tide holding, a clear afternoon. tide_1 to tide_7: just after
## each phase's rise, the storm building and the light lowering. All from one camera
## out at sea, looking up one slope, so the climbing waterline is compared directly.
## - shore_calm and shore_gale: standing on the beach at the first tide, and on the
## last land after the fifth rise, looking along the waterline: foam, chop, rain and
## the lowering light. (Seed 2's highest summit goes under at the sixth rise, so
## tide_6 and tide_7 show only sea over where the island was.)
## - underwater: below the surface just off that beach, looking up the slope.
extends Node3D
@export var stage: String = "tide_0"
@export var match_seed: int = 2
var sim: Simulation
var view: MatchView
func _ready() -> void:
sim = Simulation.new(match_seed)
sim.start_tide()
var levels: PackedFloat32Array = sim.tide.levels
var after_rise: int = 0
if stage.begins_with("tide_"):
after_rise = stage.trim_prefix("tide_").to_int()
elif stage == "shore_gale":
# The last land: on most islands the next rise covers the highest summit.
after_rise = Tide.phase_count() - 2
var elapsed: int = _elapsed_after(after_rise)
sim.tide = Tide.new(sim.tick - elapsed, levels)
sim.set_sea_level(sim.tide.level_at(sim.tick))
var shore: Array = _shore(sim.sea_level)
var edge: Vector3 = shore[0]
var inland: Vector3 = shore[1]
view = MatchView.new()
view.setup(sim, 0)
add_child(view)
view.sync()
if stage.begins_with("tide_"):
# Out at sea, looking in at this tide's waterline and the land above it.
var eye: Vector3 = edge - inland * 150.0 + Vector3(0.0, 55.0, 0.0)
var target: Vector3 = edge + inland * 70.0
target.y = sim.ground.terrain_height(target.x, target.z)
view.look_from(eye, target)
elif stage == "underwater":
# Out from the waterline until the water is a few metres deep.
var under: Vector3 = edge
for _step: int in 200:
if sim.ground.terrain_height(under.x, under.z) < sim.sea_level - 4.0:
break
under -= inland * 2.0
under.y = sim.sea_level - 1.8
var look: Vector3 = edge + inland * 20.0
look.y = sim.ground.terrain_height(look.x, look.z) + 1.0
view.look_from(under, look)
else:
# On the beach, looking along the waterline and out a little.
var along: Vector3 = inland.cross(Vector3.UP).normalized()
var stand: Vector3 = edge + inland * 5.0
stand.y = sim.ground.terrain_height(stand.x, stand.z) + 1.7
var look: Vector3 = edge + along * 45.0 - inland * 30.0
look.y = sim.sea_level
view.look_from(stand, look)
view.sync()
view.settle()
## Ticks from the tide's start to two seconds after phase `rises` - 1's rise ends, or
## into the first hold for 0.
func _elapsed_after(rises: int) -> int:
var at: float = 0.0
if rises == 0:
return roundi(20.0 * Tuning.TICK_RATE_HZ)
for index: int in rises:
var phase: Dictionary = Tuning.TIDE_PHASES[index]
at += float(phase["hold"]) + float(phase["rise"])
return roundi((at + 2.0) * Tuning.TICK_RATE_HZ)
## [where the sea at `level` meets the land, the unit direction inland from there],
## on the bearing from the highest summit whose shore rises most gently.
func _shore(level: float) -> Array:
var summit: Vector3 = sim.island.summits[0]
var best: Array = []
var best_run: float = 0.0
for bearing: int in 24:
var out: Vector3 = Vector3(cos(TAU * bearing / 24.0), 0.0, sin(TAU * bearing / 24.0))
var at: Vector3 = summit
var step: int = 0
# Down to the sea itself, not a dry hollow below its level.
while step < 500 and (sim.ground.terrain_height(at.x, at.z) > level or (sim.flood != null and not sim.flood.is_flooded(at.x, at.z))):
at += out * 2.0
step += 1
if step >= 500 or step == 0:
continue
# How far inland before the land is 12 m above the water: longer is gentler.
var run: float = 0.0
while run < 300.0 and sim.ground.terrain_height(at.x - out.x * run, at.z - out.z * run) < level + 12.0:
run += 2.0
if run > best_run:
best_run = run
best = [Vector3(at.x, level, at.z), -out]
return best if not best.is_empty() else [Vector3(summit.x, level, summit.z), Vector3.FORWARD]
+1
View File
@@ -0,0 +1 @@
uid://ujp18lcuhtt5
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "shore_calm"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "shore_gale"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_0"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_1"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_2"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_3"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_4"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_5"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_6"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "tide_7"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/sea_scene.gd" id="1"]
[node name="CaptureSea" type="Node3D"]
script = ExtResource("1")
stage = "underwater"