Renderer · interface

RainFieldOptions

Falling rain, as streaks the line batch already draws.

Explained in Hello world.

interface RainFieldOptions
import type { RainFieldOptions } from '@driftengine/core';

In depth

A drop is a segment, not a billboard, and that is the whole design. The particle pool draws round sprites with a spin, which is right for smoke and grit and wrong for water: rain in a photograph is a streak, because the drop moved while the shutter was open, and a round sprite stretched by a shader would need a new attribute and a new branch in both backends' particle programs. A segment from where a drop was to where it is says the same thing with geometry that has shipped for a year — and it gets the angle for free, since the streak runs along the velocity and the velocity is where the wind already is.

What was missing was never the mechanism. ParticlePool and the line batch both ship; what did not exist was anything that made falling water out of either, so a consumer whose weather already wetted surfaces and raised their reflectivity had three of their four acceptance criteria and no water anybody could see fall.

Drops do not fall through roofs, which is the requirement that usually turns a rain effect into a real one, and the query for it was already here: GroundSurface.sampleBand answers "is there a face in this column between these two heights", which is exactly "is something over my head". A drop under cover is not drawn. The same surface's sample is the floor it lands on, so rain stops at the ground rather than continuing to the bottom of the slab.

Nothing here reads a clock or a random number. A drop's place in the slab is a hash of its index and how many times it has fallen, so the same viewer at the same instant sees the same rain — the rule the dust field in lightVolume.ts is under, for the same reason.

Properties

NameTypeDescription
countnumberHow many drops are in the air at once.
radiusMnumberHalf-width of the box of rain kept around the viewer, metres.
heightMnumberHow far above the viewer a drop starts, metres. Also the ceiling a roof is looked for under.
speedMpsoptionalnumberFall speed. Rain reaches about 9 m/s, drizzle is nearer 2, and hail comes down at about 14.
More

The starting value only: RainField.speedMps moves it while the field is running, which is what a weather state changing under a player needs.

streakSecoptionalnumberHow much of a drop's own motion the streak shows, in seconds.
More

It is a shutter time and behaves like one: 0.02 is a crisp dash, 0.1 is the smeared rain of a long exposure. It does not affect where a drop is, only how long it looks.

groundoptionalGroundSurfaceThe ground drops land on, and the roofs they do not fall through.
clearMoptionalnumberHow near the viewer a streak may pass and still be drawn, metres. Default 1.
More

A drop that close is out of any focus a camera holds, and drawn sharp it was a bar across the frame: a streak is a world-space width, so a 6 mm drop 30 cm from the eye drew fourteen pixels thick and as long as the frame, from a city seen from the air in the rain. A streak whose nearest point is inside this distance is not drawn; the drop keeps falling, as a sheltered one does. What it gives up is rain on a lens or a visor, which this field never drew as such anyway. What would make it wrong is a view that wants drops in macro: pass 0.