---
name: ferret-weather
description: Use for weather in Ferret (@ferret/weather, @ferret/clouds): one state and presets, wind with gusts and height for physics, clouds, rain, snow, lightning, storm sea and surf, trees and grass in the wind, sand storms, tornadoes; with landscapes and physics; sea and sky to the horizon.
---

# Weather

## When to use
A scene needs wind, cloud, rain, a storm, a sea that follows the wind, surf on a shore, trees that bend and break, a sandstorm or a tornado; or a game's physics must fly or sail in the weather the player sees.

## The model
A `WeatherService` holds one state (wind, windDir, gustiness, cloudCover, convection, humidity, temperature, precipitation, thunder ...) and moves it on the world's clock (`set`, `blendTo(preset, seconds)`). Every model is a pure function of the state and the time, so peers agree. Directions: 0 = +x, 90 = +z, the way the wind blows *to*.

## Steps
1. `world.addService(new FlowService())`, then `new WeatherService({ state: 'fair', seed, sea, area, ground: terrainGround(landscape.ground, () => weather.state) })`.
2. Wind for physics: `windVector(state, x, z, heightAboveGround, t)` near the ground, `windAloft(state, h)` kilometres up. Give it to aircraft, airships, ballistics; the flow field gets it by itself.
3. Sky: `CloudField` + `CloudView` (@ferret/clouds) with `cloudFieldFor(state)`; `PrecipView`, `LightningView` round the camera.
4. Sea: `seaWaves(state)` into the water. Flight scale: `OceanView` (@ferret/levels) with `depthAt` from the landscape, `setWind(windDir)`, `setReflection(createSkyProbe(...))`. Walking scale: `SeaSurface`, `SurfView`, `floatOnSea`.
5. Near the camera: `TreesView`, `GrassView`, `RiverView`, `SnowView`, `WetSurfaces`; physics: `WeatherPhysics` after the `PhysicsHost`.
6. Commands: `weather.state|presets|set|blend|sample|sky|sea|surf|tornado|haboob|report`.

## Check afterwards
Blend each preset you offer and look from the views the game uses, on the RTX (check the renderer string). The wind the physics reads equals `weather.sample` at that point. The sea has no band at the horizon and no shimmer at a low view; no sea shows under land far away.

## What usually goes wrong
- Two copies of the weather (sliders with their own numbers): write the sliders into the service and read back from `state`.
- Compass bearings (wind *from*, 0 = north = -z) mixed with the module's angle (wind *to*, 0 = +x): convert once.
- A flat far water plane under a patch: bands and moire at the horizon; use `OceanView`.
- Sea under distant land: the ocean has no depth there; give `depthAt` (its far box covers 400 km).
- Cloud meshes are rebuilt as the camera moves: refresh the sky probe's render list each frame.
- A `ShaderMaterial` ignores the scene's fog: give the haze to the water and terrain views yourself.

## Files
- `reference/weather.md` is the guide; `reference/api-weather.md` and `reference/api-clouds.md` list every export.
- Grass and trees should also answer a rotor's wash: pass `flowMap` (a `FlowMap` of `@ferret/physics-response`) to `GrassView` and to `applyFoliageWind`; see `ferret-physics-response`.

## Files

- `reference/weather.md` — The weather as one state and what it does: clouds by genus, rain, snow and hail, lightning and thunder, blizzards; the storm sea, whitecaps, freak waves and the surf on sand, cobble, boulder and rock; rivers with rapids and waterfalls; trees that sway, shed limbs, snap and fall, leaves that shiver, waves in the grass; sand and dust storms, haboobs, the simoom; tornadoes, dust devils and waterspouts.
- `reference/api-weather.md` — every export of `@ferret/weather` with signature and doc comment
- `reference/api-weather-2.md` — every export of `@ferret/weather` with signature and doc comment
- `reference/api-weather-3.md` — every export of `@ferret/weather` with signature and doc comment
- `reference/api-clouds.md` — every export of `@ferret/clouds` with signature and doc comment
- `reference/commands.md` — 11 commands of these packages with their arguments
