# Terrain

Seeded heightfields for ground, hills and mountains, with flat areas for lots and roads.

`{"terrain": {...}}` is a geometry: a seeded noise heightfield. Put a surface material on it.

```json title="apps/docs/examples/terrain.json"
{
  "camera": { "position": [0, 14, 46], "target": [0, 4, 0], "fov": 45 },
  "lighting": { "rig": "golden_hour" },
  "environment": { "background": { "sky": {} } },
  "materials": {
    "dirt": { "preset": "gravel", "color": "#a77b5a" },
    "rock": { "preset": "rock", "color": "#6d5a7a" }
  },
  "nodes": {
    "ground": {
      "mesh": {
        "geometry": {
          "terrain": {
            "size": [160, 160],
            "height": 4,
            "scale": 25,
            "flat": { "center": [0, 10], "radius": 14, "falloff": 20 }
          }
        },
        "material": "dirt"
      }
    },
    "mountains": {
      "transform": { "position": [0, -2, -60] },
      "mesh": {
        "geometry": {
          "terrain": {
            "size": [400, 200],
            "height": 45,
            "scale": 60,
            "ridged": true,
            "flat": { "center": [0, 60], "radius": 70, "falloff": 50 }
          }
        },
        "material": "rock"
      }
    }
  }
}
```

![Render of terrain](/renders/terrain.jpg)

## Shape

- `size`: the area in world units.
- `height` and `scale`: how tall the features are and how wide.
- `octaves`: detail. `ridged: true` makes sharp mountain crests.
- `flat`: a level region with a `center`, `radius` and `falloff`, for a parking lot, a road or a stage.
- `resolution`: grid vertices per side.

## Mountains on the Horizon

Use a second, larger terrain far away with `ridged: true`, a big `height`, and a large `flat` radius so it only rises in the distance. Sink it slightly below the ground so the two flat areas don't overlap.

## API Reference

### Terrain

A noise heightfield on the XZ plane, centred on the node.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `flat` | `FlatArea` | — | Keeps a flat area around `flat.center` and ramps the noise up past `radius` over `falloff`: a level lot with hills, or mountains only on the horizon. |
| `height` | `number` | `2` | Peak height in world units. |
| `octaves` | `integer` | `5` | Noise octaves (1..8): more adds finer detail. |
| `resolution` | `integer` | `128` | Grid cells per side (2..512). Higher is smoother and heavier. |
| `ridged` | `boolean` | `false` | Sharp ridged crests (mountains) instead of rolling hills. |
| `scale` | `number` | `20` | Feature size in world units (distance between hills). |
| `seed` | `integer` | `0` | Seed for the height noise. |
| `size` | `[x, y]` | `[100,100]` | Width (x) and depth (z) in world units. |
### FlatArea

A flat region in a [`Terrain`].

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `center` | `[x, y]` | `[0,0]` | Centre `[x, z]` in the terrain's local space. |
| `falloff` | `number` | `10` | Distance over which the flat area blends back into the hills. |
| `radius` (required) | `number` | — | Radius of the flat area. |
