Skip to content

Lightning and the rain into physics (O20, part 1: F5, F6) - #1320

Merged
transfix merged 32 commits into
masterfrom
feat/weather-lightning
Nov 17, 2026
Merged

transfix merged 32 commits into
masterfrom
feat/weather-lightning

Conversation

@transfix

@transfix transfix commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

O20, part 1 of OCEAN-AND-WEATHER-ROADMAP.md: the parts of F5 and F6 that don't need O14. Stacked on #1315 (O19, rain), which is stacked on #1312 (O18). Retarget to master once those merge.

F5, lightning

  • cvc::world::weather::strikes(t, window) schedules the strikes. Each recent cell's life is cut into 1 s slots. A slot holds a strike with probability flash_rate × smoothstep of the cell's intensity from flash_onset (0.05 and 0.55 by default), a hashed draw of the seed, the cell and the slot. The strike lands within the cell's rain radius, and ground_share (0.6) of the strikes reach the ground. A strike has one to four strokes, and intensity(age) gives its light. It is a pure function of the seed, the time and the events, so every client sees the same strike at the same moment.
  • The bolt ports ABYSSAL's Lightning.js at 849ff7f4 (MIT; notice in the file header and THIRD_PARTY_NOTICES.md). The channel is grown by midpoint displacement, with forks and in-cloud crawlers, from a splitmix64 stream seeded by the strike's id. It is drawn as camera-facing ribbons with a hot core and a blue-white glow, each tapering past its ends. The mesh weather_bolt is rebuilt once per strike (at most 2048 segments) and drawn in the volume layer after the deck as a sky receiver.
  • The flash goes out as sky.flash, which the sky hands on as the uniform cloudFlash. The receivers add their albedo × the flash, the water adds it to its lit term, the far shells glow round the strike, and the background whitens. It falls off over about a kilometre. The weather hands it on a frame step ahead, because the sky ticks first, so the light lands on the bolt's frame.
  • Keys: weather.lightning (strength) and weather.flash (published). Props: flash_rate, flash_onset, ground_share and lightning.

F6, rain into physics

  • surface_class::mu_wet is each class's friction when soaked: wet asphalt 0.55, grass 0.3; indoor floors keep theirs.
  • cvc::physics::wet_friction(class, w) gives a class's friction at wetness w.
  • cvc::physics::apply_wetness(world, w) sets every material named after a surface class through world::set_material.
  • The weather node applies it in the scene's physics world from weather::wetness at the vehicles, at most twice a world second and only when the wetness moves by 1/64. The wetness is deterministic, so the friction replicates with it.
  • Keys: weather.friction (0 restores the dry friction) and weather.wetness.

Found on the way, fixed on #1315 (one commit pushed there, b7e5406): cloud_sky looked its receivers up by top-level name only, so the weather's streak mesh (a child of the weather's node) was never wired. It drew without the deck's shade and fog, and before the clouds instead of after them. Receivers are now found anywhere in the scene. That commit also fixes the streaks' ground under a camera off the terrain (NaN before), and here the same fix keeps a bolt that lands past the terrain from going NaN.

Samplers: none added. The water and the receivers get the flash as one vec4 uniform. The bolt mesh has no texture of its own; as a receiver it carries the sky's two shade samplers, which its shader does not read.

Tests

  • WorldWeather.LightningStrikesOnSchedule: windows agree with their seconds; a storm strikes only while mature, within its rain, at about the rate asked; the ground share holds; a clear sky never strikes.
  • PhysicsVehicle.RainLowersTheRoadsTractionAndItComesBackAsItDries: braking from 20 m/s, the vehicle stops in 25.2 m dry, 37.8 m soaked (within 15 % of v² / (2 μ g)), and 25.2 m three dry times later.
  • cvcgl_ariadne_realize, new section: the keys are seeded, the storm throws lightning, a finite bolt is drawn, the sky wired the bolt as a receiver, the flash reaches the shared uniform, five of eight surfaces are lowered at wetness 0.45, and they are dry again with weather.friction off. The O19 section now also checks that the sky wired the streaks.
  • Run on Windows: WorldWeather (12), WorldCloudLayer (22), ^World (411), ^Physics (180), PhysicsVehicle (25), AriadneComponents (10), AriadneLoader (39), surface (67), cvcgl_tree_version and cvcgl_ariadne_realize all pass. terrain_lab with CVCGL_LOWMEM_MAPPER=force CVCGL_TEXTURE_UNITS=16 and strikes in view logged no out-of-units warning in 140 frames.

Frame cost: terrain_lab with flash_rate: 3 (a strike about every second), arigl at 1280×720 under a storm overhead, (720 − 120) / 600, three interleaved runs. Lightning off: 177, 140 and 67 ms. Lightning on: 111, 83 and 73 ms. Other agents were building, so this shows nothing finer than "no visible cost"; the quietest pair is 67 against 73 ms. Timed directly, a new strike's bolt (51 segments on average) takes 0.05 ms to grow and mesh, and 0.7 ms (at most 1.3 ms) in setGeometry, once per strike. The flash is one uniform.

Looked at (terrain_lab with flash_rate: 3, 1280×720): a ground strike by the city from under the storm, with the ground and the buildings lit; an in-cloud strike's crawlers; the same strike from 1.6 km outside the storm. The streaks are now visibly crisper under the deck, since they draw after it.

Left for O14 (F4), noted in the roadmap:

  • one scene wind (wind.speed, wind.dir) for steeringWind(), the water, the trees and the rain's slant;
  • that wind's force on light bodies (which F6's gusts also need);
  • a gust front per cell, its speed rising and veering ahead;
  • the wind sea's lag (E4).

Not done: thunder, the near volumes' flash, lake levels (W1), the browser run, Linux and macOS.

The wet friction moved into the scene's world (9785be5, f7bb141)

Review found that the wet friction (F6) was set by cvcGL's weather node from its frame tick: at most twice a world second, into the physics world's materials. The wetness is a function of the seed, the time and the events. But two things made the physics differ by host and frame rate:

  • The step at which the friction changed depended on when a frame came, so 30 fps, 60 fps and an offscreen capture changed it at different steps.
  • A host without a renderer (ari, arisrv, a headless test) never applied it.

It is now the scene world's job, in new code in scene_weather.h:

  • scene_weather_params (and _ground, _soak, _dry) read a weather node's props. The drawn node and the world both use them, so the friction follows the storms the node draws.
  • WeatherFriction, one per weather node, is bound by SceneWorld::bind_weather in both from_scene and scene_realize. It reads weather.events and weather.friction at sync. In follow(), before the physics step, it sets the friction:
    • on the first step of each half second of world time, counted in the world clock's ticks (each step's tick comes from the clock follower);
    • when the wetness at the vehicles has moved by 1/64. The wetness is their mean, or the weather's centre when there are none.
  • weather.friction 0 dries the surfaces at the next step.
  • It publishes weather.wetness.

The weather node no longer touches the friction.

Test AriadneSceneWeather.TheRainsFrictionIsSetInTheStepOnTheClocksTicks:

  • A headless world lowers asphalt's friction to the wet ground's value at the wetness it applied.
  • The first change falls on a half-second boundary.
  • A run with uneven 0.137 s frames has the same friction as a run with a frame per clock quantum, at every tick both see.
  • weather.friction 0 dries the surfaces at the next step.

Locally (Windows Release), all of these pass: ariadne_scene_world_test (including this test), the physics suites, cvcgl_ariadne_realize (its wet-friction check now runs through the core path), cvcgl_ariadne_physics and world_weather_test.

…ts (O18)

cvc::world::weather is a pure function of its parameters, the world time and
authored events (storm, steer, rate, calm): storms on hashed slots run clear,
building, storm, clearing and clear, born upwind and timed to cross the area in
their prime, riding the steering wind. It publishes the cells, the storm field
and a rain rate for O19 and O20. A weather stream is appended to lsys::stream.
…aps built off the frame

set_storms gives each cell a storm share that feeds it, holds it besides the
fair-weather coverage and deepens its shade and far opacity. set_deck makes the
maps again for new heights; a deck deeper than its cumulus grows cumulonimbus
(ABYSSAL's height profile) whose self-shade marches the sun through the tower.
prepare_deck / run / adopt_deck build it on another thread, and the cumulus the
maps grow from is kept, so a storm deck comes in in about 150 ms. cell_up_tau is
the optical depth straight up, for dark bases.
…rrain_lab

cloud_sky reads sky.base, sky.top, sky.darkness and sky.storms live: a storm deck
is built off the frame and swapped into the same near volumes and far shells, the
ramp darkens toward a storm's, a darkened cloud's light dims as the cloud above
hides the sky, and the storms reach the far shells and the receivers as uniforms
(no new sampler). The weather node owns the model over its ground, drives the sky
and publishes weather.*; its steering wind is the sky's until O14's scene wind.
weather_controls.ari, terrain_lab's weather node, docs and the roadmap's as built.
… there are no threads

std::async cannot start a thread in single-threaded wasm (the Pages gallery,
arigl-web), so a storm coming into reach would have aborted the page. The deck's
build is now a cvc::sliced_job on the app's scheduler, as generated_world's
rebuilds are (#984): on the background pool natively, a few milliseconds a frame
on the scheduler thread where there are no threads. cloud_layer::step builds a
deck a unit at a time (a variant's map, one layer of its self-shade, one row of
its shade), bit-identical to building it at once. deck_threading: cooperative
forces the sliced path natively; cvcgl_ariadne_realize runs the storm both ways.
…er's arrays

The redeployed terrain_lab still ran out in every water draw: headless
Chrome logged 2,318 out-of-units warnings in 75 s once the water came
up. VTK sizes its texture-unit table from GL_MAX_TEXTURE_IMAGE_UNITS,
which is 32 on a desktop GL but 16 in WebGL2. bindShaderTextures first
reserved a fixed 8 units for the low-memory mapper's emulated vertex
arrays, which left a draw 8 for its own textures, and the water binds
10 (three cascades, three coast grids, the wake, the bed, two
cloud-shade textures).

- LowMemoryPolyDataMapper::arrayTextureUnits(): the arrays the draw
  under way takes, vtkDrawTexturedElements::Arrays (bound in
  RenderPieceStart, before UpdateShaderEvent fires). bindShaderTextures
  reserves that many when the drawing mapper (the event's caller, or
  the node's own) is one of ours, else 8 as before.
- A texture that still finds no unit is left unbound, so it no longer
  sets a -1 sampler, which was a second GL error every draw. cvcGL
  names the node and texture once.
- ViewportManager::limitTextureUnits(n) and $CVCGL_TEXTURE_UNITS cap
  VTK's table, put back at the start of each render after a GL state
  reset. With CVCGL_LOWMEM_MAPPER=force, a native run draws within the
  browser's budget. Native terrain_lab that way logged 1,440 warnings
  with the fixed reserve ("far" and "near" out of units for uWake: 16
  in all, 8 kept, 10 shader textures), and 0 with this change.
- cvcgl_ariadne_realize: the water (with a swell, so the swash and coast
  grids are on), cloud_sky's shade and a shadow-casting sun, drawn with
  the low-memory mapper at 16 units, log no out-of-units warning. The
  count is checked to hear VTK's warning.
- ARIADNE.md: the browser's texture units, natively.
- The comment #1304 added said WebGL2 gives VTK 32 units; it gives 16.
…s wetness (O19)

weather::recent gives the cells whose life reached into a window, alive or gone;
rain_radius is where a cell's field passes the rain onset; wetness is how long a
recent storm's rain lay over a point over a soak time, times its drying since,
the CPU twin of the wet ground the sky draws and the friction O20 will read.
… and fog (O19)

The weather node hands cloud_sky the recent storms' tracks and the rain's
constants (sky.rain, sky.rain_k) and draws the streaks near the camera: a port of
ABYSSAL's Rain, drops placed and moved in the vertex shader as a closed form of
time, slanted by the scene wind's one accessor. cloud_sky draws rain shafts below
the cloud base in its far shells, wets and darkens its receivers along the tracks
and dries them after, puts procedural raindrop rings into the water's normal, and
thickens a distance fog with the rain at the camera, all as uniforms: no sampler
joins the ground, the buildings, the roads, the trees or the water. terrain_lab's
sky lists the streaks; the Weather panel has the rain's keys.
… off the terrain

cloud_sky looked its receivers up among the scene's top-level names, so the
weather's streak mesh (weather_rain, a child of the weather's node) was never
wired: it drew without the deck's shade and fog, and in the volume layer
before the clouds instead of after them. A receiver is now found anywhere in
the scene. The streaks' ground under a camera off the terrain is the height at
the terrain's edge, not NaN. cvcgl_ariadne_realize checks that the sky wired
the streaks.
weather::strikes(t, window) lists the strikes of the last window weather
seconds: each recent cell's life in 1 s slots, a slot holding a strike with
probability flash_rate times a smoothstep of the cell's intensity from
flash_onset, a hashed draw of the seed, the cell and the slot, at a hashed
point within its rain radius; ground_share of them reach the ground. A
lightning_strike carries its id (the seed of its bolt), its time, its point
and one to four strokes, and intensity(age) gives its light. A pure function
of the seed, the time and the events, so every client sees the same strike.
Test: WorldWeather.LightningStrikesOnSchedule.
…e (O20)

surface_class::mu_wet is each class's friction soaked (wet asphalt and
concrete 0.55, dirt 0.35, gravel and sand 0.45, grass 0.3; indoor floors keep
theirs). cvc::physics::wet_friction(class, w) runs mu toward it by the
wetness, and apply_wetness(world, w) sets every material named after a
surface class (as add_world_geometry names them) through world::set_material.
Test: PhysicsVehicle.RainLowersTheRoadsTractionAndItComesBackAsItDries, a
storm crossing the road: braking from 20 m/s the vehicle stops in 25.2 m dry,
37.8 m soaked and 25.2 m three dry times later.
…(O20)

The weather node draws the brightest strike of the moment as a bolt, a port
of ABYSSAL's Lightning (Lightning.js at 849ff7f4, MIT; notice in the header
and THIRD_PARTY_NOTICES.md): a channel from the cloud base to the ground by
midpoint displacement, fading forks and in-cloud crawlers, grown from the
strike's id, drawn as camera-facing ribbons (a hot core and a blue-white
glow, tapering past their ends) in the mesh <id>_bolt, rebuilt once a strike
and drawn after the deck as a sky receiver. Its ground point is the ground's
height, at the terrain's edge past it.

The flash goes to the sky as sky.flash, a frame step ahead since the sky
ticks first, and from there as one vec4 uniform, cloudFlash: the receivers
add their albedo times it, the water its lit term, the far shells glow round
the strike and the background whitens. No sampler is added.

In a scene with a physics world the node sets the surface materials'
friction from weather::wetness at the vehicles (apply_wetness), at most twice
a world second and only when the wetness moves by 1/64; weather.friction off
restores the dry friction. Keys weather.lightning, .flash, .friction and
.wetness, on the Weather panel; props flash_rate, flash_onset, ground_share,
lightning and friction. terrain_lab lists weather_bolt among the receivers.
cvcgl_ariadne_realize covers the lightning, the bolt's wiring and the
friction. Docs: ARIADNE.md, and "As built (O20, part 1)" in the roadmap,
with what F4 needs from O14.
Conflicts:
- THIRD_PARTY_NOTICES.md: both sides extended the ABYSSAL paragraph after
  OceanFFT.js. Kept master's gusts and currents sentence, then the storm
  deck's and the weather model's. The summary line now names the wind's
  gusts and currents (wind_field.h, current.h) beside the storm maps.
- src/cvc/tests/CMakeLists.txt: both test loops list world_weather_test
  (this branch) and ocean_wind_test (master).
Conflict:
- THIRD_PARTY_NOTICES.md, the ABYSSAL summary line: kept the storms merge's
  wind gusts and currents, and this branch's rain streaks.
water_node.cpp merged cleanly. The water lighting's three O19 swaps still
find their lines in #1311's shader, and vWaterRest is still there.
…ning

Conflict:
- THIRD_PARTY_NOTICES.md, the ABYSSAL summary line: kept the wind gusts and
  currents, the rain streaks and this branch's lightning bolts.
water_node.cpp merged cleanly. The flash's swap into the water lighting
still finds its line.
master fails to build arisrvx's python_engine.cpp: #1302 (bridged users)
added room(), bridge_presence(), bridge_absent(), bridge_post() and
listen_chat() calling server_link() with no argument, written against the
process-wide server link that the P0a cleanup replaced with the module's
own state, server_link(PyObject *self). Each of the five now names its
module argument self and passes it, as the other server ops (lent(),
publish(), ...) already do.

Found in #1324's pycvc-linux / cp312 job (run 43956686020),
which builds the PR merged with master.
…ther-storms

# Conflicts:
#	src/cvcGL/test/cvcgl_ariadne_realize.cpp
 into feat/weather-rain

# Conflicts:
#	docs/ARIADNE.md
#	src/cvcGL/test/cvcgl_ariadne_realize.cpp
The realize suite runs every node type's checks in one process. In a
Linux Debug job (Xvfb, llvmpipe) it took 250.6 s, 50 s under the 300 s a
test without a TIMEOUT gets; on a slower runner (#1309's Debug job, where
PhConvoy and Ewave also ran about 1.3x longer) it timed out on all three
attempts. As cvcgl_ewave, cvcgl_wake and cvcgl_volren_node have, it gets
a budget of its own with headroom, so only a real hang fails it.
Merged on #1312's final head (a6c28ab) as the base, so the squash's copy of #1312 meets this
branch's and only the rain's own changes are applied over master.
…into feat/weather-lightning

# Conflicts:
#	inc/cvc/physics/world_geometry.h
#	src/cvc/physics/world_geometry.cpp
Base automatically changed from feat/weather-rain to master November 17, 2026 14:20
…ightning

Merged on #1315's final head (0c16793) as the base, so the squash's copy of #1315 meets this
branch's and only the lightning's own changes are applied over master.
…ther-lightning

# Conflicts:
#	docs/ARIADNE.md
…ther-lightning

# Conflicts:
#	docs/ARIADNE.md
… physics step on the clock

The wet friction (O20, F6) was set by cvcGL's weather node from its frame tick: at most twice a world
second, into the physics world's materials from the next step on. The wetness is a function of the
seed, the time and the events, but the step at which the friction changed depended on when a frame
came (30 fps, 60 fps or an offscreen capture changed it at different steps), and a host without a
renderer (ari, arisrv, a headless test) never applied it, so one document's physics differed by host
and frame rate.

The friction is physics, so the scene's world now sets it. scene_weather.h:
- scene_weather_params / _ground / _soak / _dry read a weather node's props; the drawn node and the
  world both use them, so the friction follows the storms the node draws.
- WeatherFriction (one per weather node, SceneWorld::bind_weather; from_scene and scene_realize both
  bind it) reads weather.events and weather.friction at sync, and sets the friction in follow()
  before the physics step: on the first step of each half second of world time, counted in the
  world clock's ticks (each step's tick from the clock follower), when the wetness at the vehicles
  (their mean; the weather's centre with none) has moved by 1/64. weather.friction 0 dries the
  surfaces at the next step. It publishes weather.wetness. A restart sets it again at the next step.

The weather node no longer touches the friction (its frame tick is gone) and takes its params and
soak/dry from scene_weather.

Test: AriadneSceneWeather.TheRainsFrictionIsSetInTheStepOnTheClocksTicks. A headless world lowers
asphalt's friction to its soaked value; it first changes on a half-second boundary; a run with uneven
0.137 s frames has the same friction as one with a frame per clock quantum at every tick both see;
weather.friction 0 dries it at the next step.
…ness applied (the storm moves on and the ground begins to dry), not a full soak
@transfix
transfix enabled auto-merge (squash) November 17, 2026 22:00
@transfix
transfix merged commit 3ed9f3e into master Nov 17, 2026
30 checks passed
@transfix
transfix deleted the feat/weather-lightning branch November 17, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant