Log inGet started
World

Procgen Effects Showcase

Branchmain
Branchesmain
Commit99ff90d12c

README.md

StormDirector

StormDirector handles everything about a lightning strike apart from the particles. The storm graph (the Generator on the same entity) owns the bolts, rain, splashes, sparks and smoke, and runs on one looping clock. StormDirector reads that same clock every frame and, through the shared storm.schedule, pours each strike's light over the rest of the scene: the sun swings to the bolt and throws the tower's shadow, point lights blaze at the strike, the cloud deck and the puddles light up, and the thunder follows at the speed of sound. Between strikes the values hold still, so its resting cost is one clock read.

The fx_storm scene uses it on the storm entity, next to the Generator that plays the storm.storm graph, with moonIntensity = 0.3 and ambientIntensity = 0.05.

It requires storm.schedule. It runs at executionOrder = 60. It finds these by name, and finds them again every 2 seconds, whenever one of their entities is gone, and while it is still looking for the generator:

NameWhat it reads
sunLight: the moonlight that swings toward each bolt
ambientLight: the ambient level
FlashKeyLight: the point light that blazes at the strike
FlashFillLight: the fill light high in the cloud
stormGenerator: the storm clock
Thunder1, Thunder2, Thunder3Audio: the thunder sounds
storm_sky, storm_groundmaterials, resolved once as assets

Fields

FieldTypeDefaultDescription
flashGainnumber1.0Scene-wide brightness of a strike's light, as a multiplier on the tuned defaults.
moonIntensitynumber1.7Moonlight before any strike: the sun light's intensity between strikes.
ambientIntensitynumber0.26The ambient light's intensity between strikes.
thunderVolumenumber1.0Thunder loudness.

All fields are Sync.

What each frame does

  1. Reads the generator's time and turns it into the storm phase with schedule.phase.
  2. Sums every strike's weighted envelope into flash (held at most 3, then scaled by flashGain) and its weighted afterglow into glow (held at most 1.2). The strike with the largest envelope + afterglow leads the lighting.
  3. Carries each strike's target and top from the graph's own space into the world through the storm entity's position and rotation (Transform.localToWorld).
  4. In play (update), cues the thunder. Each strike's thunder plays when the phase passes the strike time plus the distance from the camera drawing the viewport to the point halfway up the strike, divided by 343. The strikes take turns over Thunder1 to Thunder3; the volume is thunderVolume (times 0.85 for a ground strike) and each strike gets its own pitch near 1.
  5. When flash, glow or the leading strike has moved since the last write, it updates:
    • the sun's direction, lerped from the moonlight direction toward the bolt's direction as the flash burns, its intensity (moonIntensity + flash * 7 + glow * 0.6) and its colour, from { 0.36, 0.46, 0.78 } toward { 0.72, 0.80, 1.0 };
    • the ambient light's intensity (ambientIntensity + flash * 0.55 + glow * 0.08);
    • FlashKey, moved near the leading strike, at intensity flash * 9000 + glow * 700, and FlashFill at flash * 7000 + glow * 500;
    • storm_sky's flash and bolt_dir (the direction from the camera drawing the viewport toward the bolt's top), and storm_ground's flash and bolt_pos (the strike target).

Lifecycle

  • update(dt): runs the frame above with thunder cues.
  • editorUpdate(dt): runs the same frame, skipping the thunder cues.

Both use dt when given and 0.016 otherwise.