---
name: ferret-terrain
description: Use to make landscapes in Ferret from a description: hills, mountains, deserts, swamps, forest, tundra, ice, icebergs, the Moon. Relief ops, erosion, biomes, the ground query, chunk view, rocks and plants made in code, rivers and lakes, avalanches, ground in physics.
---

# Landscapes

## When to use
A level needs ground that is generated, not modelled: a valley, a dune sea, a swamp, a field of icebergs, a lunar plain; or a game needs to ask what the ground is at a point.

## The model
A `TerrainSpec` (`{ version: 1, seed, relief: [...] }`) lists operations (`noise`, `shape`, `terrace`, `river`, `erode`, `lake`, `pond`, `paint`, `import`). The height is a pure function of (seed, x, z), so tiles at any size, collision, view and queries agree. `Ground` adds climate, 25 biomes, layers, soil, surface, water.

## Steps
1. Write the spec; check it with `validateSpec` (issues have a path).
2. `new Ground({ spec, climate })`; `ground.sample(x, z)` answers height, normal, slope, biome weights, layer, soil, surface, wetness, water.
3. Draw: `new TerrainView(scene, { ground, cell, levels, radius, shadows: true })` and call `update([x, y, z])` each frame; `ScatterView` for rocks and plants (`ROCKS`, `PLANT_SPECIES`, generated in code). A game's look: `paint` (colour per vertex, a 4th value is data in the alpha) and `material` (its own standard/PBR material: world uv, geomorph plugin, opaque); `water: 'inland'` with a sea of its own (`OceanView`), `setWaterReflection(skyProbe)`.
4. Physics: `registerSurfaces(host.materials)`, `CollisionChunks(kernel, ground)` + `track(body)` + `update()`, `toTerrain(ground, region)` for digging and sinking.
5. Water and hazards: `relief.waterAt`, `riverProfile`, `waterfalls`; `avalancheHazard`, `slide`, `rockfall`; ice: `makeIceberg`, `floatation`, `settle`.

## Check afterwards
Render from eye height with a low sun and compare with a photograph of the same kind of place; hollows must read as hollows. Run on the RTX and check the renderer string. Tiles must agree at shared edges; the validator must pass.

## What usually goes wrong
- Everything is one biome: the test ground sits at 0 m, which is coast. Add a base height or a `zones` biome map.
- `erode` is slow at a fine `step`: use 48 m for flight scale and keep fine steps for small areas. A wide eroded band stalls the first flight over it (a block is ~0.2 s): mask it, or use ridged noise with `warp`.
- A lake kilometres wide: `pond`, not `lake` (which sees only pits smaller than its block).
- Grey slabs or walls at chunk edges on the loading screen: the build budget is one chunk a frame; raise `o.buildsPerUpdate`/`o.buildMs` while the splash is up.
- The page shows through the ground: vertex alpha used as coverage; a game material must be opaque (`TerrainView` sets it).
- A hole while moving: never build chunks yourself; `TerrainView.update` keeps old chunks until new ones exist.
- Light from below or no cast shadows turns craters and dunes inside out.
- Farmland and volcanic fields are `manual` biomes: they come only from `zones`.
- Havok has no height field: use `CollisionChunks` (mesh tiles), not a heightmap.

## Files
- `reference/terrain.md` is the guide for this module; `reference/api-terrain.md` lists every export.
- The terrain package's `GrassView` takes an optional `flowMap` so local air (a rotor's wash) bends the blades; see `ferret-physics-response`.

## Files

- `reference/terrain.md` — Landscapes from a description: relief as a pure height function, erosion, climate and biomes, chunked view, rocks and plants made in code, ice and water, mountain hazards, and the ground in the physics world.
- `reference/api-terrain.md` — every export of `@ferret/terrain` with signature and doc comment
- `reference/api-terrain-2.md` — every export of `@ferret/terrain` with signature and doc comment
- `reference/api-terrain-3.md` — every export of `@ferret/terrain` with signature and doc comment
- `reference/commands.md` — 16 commands of these packages with their arguments
