@ferret/terrain
Landscapes from a description: relief as a pure height function (noise, shapes, erosion, rivers, lakes, edits), climate and 25 biomes, the ground query, the chunk view, rocks and plants made in code, icebergs with real buoyancy, mountain hazards and the ground in the physics world.
Read the guide: how to use it →
Classes
BiomeRegistry class
class BiomeRegistryconstructor(defs: BiomeDef[] = []) | |
register(d: BiomeDef): this | |
replace(d: BiomeDef): this | a game replaces a shipped biome by its own |
get(id: string): BiomeDef | |
has(id: string): boolean | |
list(): BiomeDef[] |
packages/terrain/src/biomes.ts:8
BiomeSelector class
class BiomeSelectorconstructor(readonly registry: BiomeRegistry, readonly zones: BiomeZone[] = [], private readonly sharpness = 3) | |
weights(x: number, z: number, i: BiomeInput, out: Record<string, number> = {}): Record<string, number> | the weights of the biomes at a place, summing to 1; entries under 2 percent are dropped |
packages/terrain/src/biomes.ts:45
ChunkPlanner class
class ChunkPlannerreadonly cells: number | |
readonly rootSize: number | |
constructor(readonly o: PlannerOptions) | |
sizeOf(level: number): number | |
plan(cx: number, cz: number): Chunk[] | the chunks to show with the camera at (cx, cz), coarse to fine; the sizes of neighbours differ by at most a factor of two |
morphRange(c: Chunk): { start: number; end: number } | the distance within which this chunk should be at full detail, and where the morph to the coarser surface begins and ends (fractions of the split distance) |
packages/terrain/src/chunks.ts:46
Climate class
class Climateconstructor(private readonly relief: Relief, spec: ClimateSpec = {}, seed = relief.seed) | |
at(x: number, z: number, height = this.relief.height(x, z), out: ClimateSample = { temperature: 0, moisture: 0, exposure: 0 }): ClimateSample |
packages/terrain/src/climate.ts:26
CollisionChunks class
class CollisionChunksStatic collision tiles round the bodies you track. The tile at (i, j) is always the same mesh (the relief is point-evaluated), built on demand and dropped when no tracked body is near. Bodies see the same surface the view draws, because both come from Relief.
built: number | |
constructor(private readonly kernel: Pick<PhysicsKernel, 'addBody' | 'removeBody'>, private readonly ground: Ground, private readonly o: CollisionOptions = {}) | |
track(b: Body | (() => [number, number, number])): () => void | follow a body (its position is read each update), or a function that gives a position |
update(): number | Build the tiles the tracked bodies need (within the budget) and drop the ones they left. Returns the number of tiles standing. |
prime(): number | every tile needed right now (before a body is dropped in) |
get count(): number | |
dispose(): void |
packages/terrain/src/physics.ts:69
GrassView class
class GrassViewreadonly root: BABYLON.TransformNode | |
readonly mesh: BABYLON.Mesh | |
readonly material: BABYLON.ShaderMaterial | |
constructor(readonly scene: BABYLON.Scene, readonly o: GrassViewOptions) | |
setLight(l: { sun?: V3; sunColor?: V3; ambient?: V3; haze?: V3; hazeDensity?: number; exposure?: number }): void | the light changed (time of day, weather): the values the terrain takes; a moved sun rebuilds the cells for their shadows |
setHaze(haze: V3, density: number): void | |
update(camera: V3): GrassViewStats | build the cells the camera needs (within the budget), drop those it left, and draw the ranks each cell's distance keeps |
prime(camera: V3): GrassViewStats | build every cell the camera needs now, regardless of the budget (a level's first frame) |
stats(): GrassViewStats | |
dispose(): void |
packages/terrain/src/grass-view.ts:296
Ground class
class Groundreadonly memory: GroundMemory | footprints, tracks and wakes pressed into this ground; heightAt includes them |
readonly relief: Relief | |
readonly climate: Climate | |
readonly registry: BiomeRegistry | |
readonly selector: BiomeSelector | |
constructor(o: GroundOptions) | |
sample(x: number, z: number, height?: number, normal?: [number, number, number]): GroundSample | |
softnessAt(x: number, z: number): string | the key of SOFTNESS for the ground at a place: its dominant layer, mud when it is wet clay or silt, nothing (rock) for layers that take no print |
heightAt(x: number, z: number): number | the height of the ground with its prints, metres |
press(x: number, z: number, radius: number, mass: number): number | a foot or wheel at (x, z): presses the ground by what it is made of; returns the depth of the print |
layerWeights(x: number, z: number, height?: number, normal?: [number, number, number]): Record<string, number> | every layer's weight at a place (summing to 1), for the splat of the view and for blends of sound and friction |
sampleNear(x: number, z: number): GroundSample | sample(x, z), but the one layerWeights made at this very point a moment ago when there is one (a chunk's colours ask the layers and then the crowns' cover at the same lattice point: one biome lookup, not two) |
packages/terrain/src/ground.ts:31
GroundMemory class
class GroundMemoryreadonly cell: number | |
version: number | grows when anything changes, so a view knows to refresh |
constructor(o: MemoryOptions = {}) | |
offset(x: number, z: number): number | the height offset at a point, metres (negative: dented; positive: a pushed-up rim), bilinear between cells |
press(x: number, z: number, radius: number, load: number, surface: string | Softness): number | Press the ground with a round foot of radius metres and a load in kPa (a 80 kg walker on 0.03 m2 of boot is 26 kPa; a car wheel 200 kPa). surface names a SOFTNESS entry (or pass a Softness). Returns the depth of the deepest dent made (0 when the ground does not take a print). |
track(x0: number, z0: number, x1: number, z1: number, radius: number, load: number, surface: string | Softness): number | a track: presses along the segment (x0, z0) to (x1, z1), a stamp every half radius |
step(dt: number): void | time heals the ground: each remembered cell relaxes towards zero at its surface's rate; empty tiles are forgotten |
get cells(): number | how many cells hold a memory right now |
clear(): void |
packages/terrain/src/memory.ts:40
GroundTextures class
class GroundTexturesreadonly slots: Record<string, number> | layer -> its slot in the shader's tables (the splat option of the chunk build) |
readonly gain: Float32Array<ArrayBuffer> | per layer slot: rgb colour gain and metres per repeat; rgb far colour (linear) and the set's index in the arrays |
readonly far: Float32Array<ArrayBuffer> | |
albedo: BABYLON.RawTexture2DArray | |
detail: BABYLON.RawTexture2DArray | |
readonly sets: string[] | |
static async load(scene: BABYLON.Scene, src: GroundImageSource, o: GroundTexturesOptions): Promise<GroundTextures> | |
looks(base: Record<string, LayerLook> = LAYER_LOOK): Record<string, LayerLook> | the far colour of each layer (the vertex colour the chunks bake): the set's mean colour as the shader tints it, so near and far agree |
dispose(): void |
packages/terrain/src/ground-textures.ts:43
HeightTile class
class HeightTileA square block of heights: n + 1 vertices per edge plus a ring of border samples round it.
readonly stride: number | |
constructor(readonly x0: number, readonly z0: number, readonly size: number, readonly n: number, readonly border: number, readonly heights: Float32Array) | |
get step() | |
at(i: number, j: number): number | the height at vertex (i, j), i and j from -border to n + border |
normalAt(i: number, j: number, out: [number, number, number] = [0, 1, 0]): [number, number, number] | the unit normal (y up) at vertex (i, j) by central differences; needs i, j within -border + 1 .. n + border - 1 |
range(): { min: number; max: number } | lowest and highest vertex of the tile proper (not the border) |
packages/terrain/src/relief.ts:374
Landscape class
class Landscapespec: TerrainSpec | |
climate: ClimateSpec | |
zones: BiomeZone[] | |
version: number | grows with every change, so a view knows to refresh |
get canUndo(): boolean | |
get canRedo(): boolean | |
undo(): boolean | go back one change (a brush stroke counts as one); returns false when there is nothing to undo |
redo(): boolean | |
constructor(o: LandscapeOptions) | |
get ground(): Ground | |
onChange(f: (version: number) => void): () => void | |
validate(): Issue[] | |
addOp(op: ReliefOp, at?: number): number | |
setOp(i: number, op: ReliefOp): void | |
patchOp(i: number, patch: Record<string, unknown>): void | |
removeOp(i: number): void | |
moveOp(from: number, to: number): void | |
addZone(z: BiomeZone): number | |
removeZone(i: number): void | |
setClimate(c: ClimateSpec): void | |
brush(b: Brush): number | Raise, lower, smooth or flatten the ground under a round brush; the strokes are stored as sparse tiles in the spec. Returns the number of lattice samples changed. |
toJSON(): { spec: TerrainSpec; climate: ClimateSpec; zones: BiomeZone[] } |
packages/terrain/src/landscape.ts:15
LatticeCorrection class
class LatticeCorrectionA correction field computed block by block. compute gets the heights below on a lattice (with a border) and returns the new heights; the stored delta is new - old. A point reads the delta of the blocks around it, blended by weights that fade to zero at each block's outer edge.
constructor(private below: Below, private step: number, private block: number, private border: number, private compute: (h: Float32Array, nx: number, ny: number) => Float32Array, private seedKey = '') | |
at(x: number, z: number): number |
packages/terrain/src/erosion.ts:85
PaintLattice class
class PaintLatticesparse lattice of heights added to the ground: the author's brush strokes. Bilinear between lattice samples, so tiles of the lattice have no seams.
readonly step: number | |
constructor(readonly op: PaintOp) | |
sampleLattice(ix: number, iz: number): number | |
at(x: number, z: number): number | |
set(x: number, z: number, value: number): void | set one lattice sample (the nearest to x, z) and keep the spec's tile list in step |
packages/terrain/src/relief.ts:318
PrintsView class
class PrintsViewreadonly mesh: BABYLON.Mesh | |
constructor(readonly scene: BABYLON.Scene, readonly ground: Ground, o: PrintsViewOptions = {}) | |
update(camera: [number, number, number]): void | call once a frame with the camera position; does nothing until the ground has a memory near the camera |
dispose(): void |
packages/terrain/src/prints-view.ts:15
Relief class
class Reliefreadonly seed: number | |
readonly seaLevel: number | |
constructor(spec: Pick<TerrainSpec, 'seed' | 'relief'> & { seaLevel?: number }) | |
height(x: number, z: number): number | the ground height at (x, z), metres |
gradient(x: number, z: number, e = 1): [number, number] | (dh/dx, dh/dz) by central differences over e metres each side |
normal(x: number, z: number, e = 1): [number, number, number] | unit normal, y up |
slope(x: number, z: number, e = 1): number | rise over run |
river(x: number, z: number): RiverHit | null | the nearest river of the spec at (x, z), or null where none reaches (water width + bank); the bed height is height(x, z) |
addWater(source: WaterSource): () => void | Water the operations do not make: a river or a pond a game already has (a level's own river line), drawn and flowing as the relief's. Asked before the relief's own water; where the source gives a level above the ground there is water. Returns a function that takes it away again. |
addedFlow(x: number, z: number): [number, number] | null | the flow of an added water source at x, z (m/s along x and z), or null when no added source covers the point or it gives none |
waterAt(x: number, z: number): { level: number; kind: 'sea' | 'lake' | 'river' } | null | |
riverLines(): { index: number; points: Vec2[]; width: number; widthEnd: number; depth: number }[] | the river operations: spec index, centre line and the nominal depth (for profiles and waterfalls) |
paintLattices(): readonly PaintLattice[] | the lattices of the paint operations, in spec order (the editor writes brush strokes into them) |
tile(o: TileOptions): HeightTile | a block of heights; neighbouring tiles of one level agree at their shared edge exactly, and a fine tile equals a coarse one at the coarse vertices |
packages/terrain/src/relief.ts:399
ScatterView class
class ScatterViewreadonly root: BABYLON.TransformNode | |
constructor(readonly scene: BABYLON.Scene, readonly o: ScatterViewOptions) | |
clock(): number | seconds since this view was made: the clock the cells' dissolve-in runs on |
setLight(l: { sun?: [number, number, number]; sunColor?: [number, number, number]; ambient?: [number, number, number]; haze?: [number, number, number]; hazeDensity?: number; exposure?: number }): void | the light changed (time of day, weather): the same values the terrain takes |
update(camera: [number, number, number]): number | Build the cells the camera needs, within the budget, and drop the cells it has left. Returns the number of individuals on show. |
count(): number | |
drawCalls(): number | |
prime(camera: [number, number, number], radius = Infinity): number | build the cells in range at once (loading screens); with a radius only the cells whose centre lies within it, the rest grows in the normal frames |
dispose(): void |
packages/terrain/src/scatter-view.ts:166
SunShadow class
class SunShadowreadonly map: BABYLON.RenderTargetTexture | the depth map (red = depth 0..1 from the sun, 1 where nothing casts) |
constructor(readonly scene: BABYLON.Scene, readonly o: SunShadowOptions) | |
get texel(): number | the texel's size on the ground, metres |
setSun(sun: V3): void | the sun moved (time of day) |
addCaster(mesh: BABYLON.AbstractMesh, depth: BABYLON.Material): void | a mesh that casts, drawn into the map with depth (a material with the mesh's own vertex shader and SUN_SHADOW_DEPTH_FRAG) |
removeCaster(mesh: BABYLON.AbstractMesh): void | |
receive(m: BABYLON.ShaderMaterial): void | a material built with SUN_SHADOW_GLSL (uniforms sunShadowMatrix, sunShadowParams; sampler sunShadowMap): it gets the map and follows it |
follow(camera: BABYLON.Camera): void | place the square for a camera: round it, shifted ahead along its look, snapped to whole texels |
place(c: V3): void | place the square round a point |
dispose(): void |
packages/terrain/src/sun-shadow.ts:67
TerrainView class
class TerrainViewreadonly planner: ChunkPlanner | |
readonly root: BABYLON.TransformNode | |
time?: number | the simulated time for the ripples, seconds; the host may set it (it defaults to the wall clock) |
constructor(readonly scene: BABYLON.Scene, readonly o: TerrainViewOptions) | |
setSun(sun: V3): void | the sun moved: the shader follows at once; baked shadows are rebuilt chunk by chunk under the build budget |
setWaterColors(c: { shallow?: V3; deep?: V3; sky?: V3 }): void | the colours the water shows (shallow, deep, and the sky it reflects when no sky cube is given); only the given ones change |
setWaterResponse(map: { readonly size: number; readonly cell: number; readonly originX: number; readonly originZ: number; readonly data: Float32Array; readonly active: boolean; readonly version: number; readonly rings?: { readonly packed: Float32Array; readonly max: number } } | null): void | What moves the water near the player (a jet's dent, rings, a wash; WaterResponseMap of |
setWaterReflection(tex: BABYLON.BaseTexture | null): void | the sky the water mirrors: a cube texture of the sky and the clouds (e.g. createSkyProbe of |
setHaze(haze: V3, density: number): void | the air changed (a sandstorm, fog): haze colour and density per metre, for the terrain, its water and falls |
setExposure(exposure: number): void | the camera's exposure changed (it metered a snowfield, the eye adapted): the land and its haze, the same value for the plants and the grass |
meter(at: V3, radius = 300, looks?: Record<string, LayerLook>): number | the mean albedo (linear) of the ground round a place, from its layers' colours: what a camera's meter sees (see meteredExposure) |
setLight(sun: V3, sunColor?: V3, ambient?: V3, haze?: V3): void | the lighting changes with the time of day |
update(camera: V3): TerrainViewStats | Plan for the camera position and build what the budget allows. Call once a frame. |
stats(pending = this.lastPlan.filter(c => this.live.get(c.id)?.ver !== this.ver).length): TerrainViewStats | |
coveredAt(x: number, z: number): boolean | whether some chunk on show covers the point (there must never be a hole while chunks are replaced) |
prime(camera: V3, radius = Infinity): TerrainViewStats | build everything planned at once (loading screens, tests, screenshots) |
primeStep(camera: V3, ms = 30): TerrainViewStats | a slice of prime: builds what is planned for at most ms milliseconds (always at least one chunk), so a loading screen keeps drawing between slices; returns the stats (pending 0 means all is built) |
dispose(): void |
packages/terrain/src/view.ts:251
Functions
addTerrainMorph function
function addTerrainMorph(m: BABYLON.Material): voidpackages/terrain/src/view.ts:86
avalancheHazard function
function avalancheHazard(relief: Relief, x: number, z: number, o: { looseSnow?: number; wind?: number } = {}): number0..1 how likely a slab is to release at a place: steep enough (30-45 degrees), with loose snow, on a slope facing away from the wind, not too rough
packages/terrain/src/hazards.ts:12
bakeGround function
function bakeGround(recipe: GroundRecipe, side: number, seed = 1): GroundMapsbake a recipe into the four maps of a library texture set
packages/terrain/src/ground-sets.ts:306
billow function
function billow(x: number, z: number, seed: number, o: FbmOptions = {}): numberrounded hills, 0..1
packages/terrain/src/noise.ts:97
buildChunkMesh function
function buildChunkMesh(src: Relief | Ground, chunk: Chunk, o: BuildOptions = {}): ChunkMeshOne chunk built at once (the steps run to the end).
packages/terrain/src/chunks.ts:199
buildChunkMeshSteps function
function* buildChunkMeshSteps(src: Relief | Ground, chunk: Chunk, o: BuildOptions = {}): Generator<void, ChunkMesh, void>One chunk built in steps: the generator yields after every row of the work (heights, then the layers' colours and crowns), so a caller can stop when its frame budget is used and go on in the next frame; it returns the mesh.
packages/terrain/src/chunks.ts:155
buildWaterfallMesh function
function buildWaterfallMesh(wf: { x: number; z: number; height: number; run: number; width: number }, level: number, dir: [number, number], seg = 12): FallMeshThe curtain of a waterfall: a ribbon as wide as the river, hanging from the lip to the foot of the drop and leaning out slightly, so it reads as falling water.
dir is the unit direction of the flow (x, z) at the lip.
packages/terrain/src/water-mesh.ts:81
buildWaterMesh function
function buildWaterMesh(relief: Relief, chunk: Chunk, n = 48, o: { /** leave the sea out: lakes and rivers only */ noSea?: boolean } = {}): WaterMesh | nullThe water of a chunk, or null when the chunk has none. n cells along the edge (default 48).
packages/terrain/src/water-mesh.ts:70
buildWaterMeshSteps function
function* buildWaterMeshSteps(relief: Relief, chunk: Chunk, n = 48, o: { /** leave the sea out: lakes and rivers only */ noSea?: boolean } = {}): Generator<void, WaterMesh | null, void>The water of a chunk in steps (the generator yields after every row of water queries; it returns the mesh or null), so a caller can spread the build over frames.
packages/terrain/src/water-mesh.ts:24
canopyAt function
function canopyAt(species: Species[], weights: Record<string, number>, x: number, z: number, seed: number): { cover: number; height: number }The tree canopy a far view draws in place of the trees (TerrainViewOptions.canopy): the part of the ground the crowns cover (0..1) and their mean height,
from the same species, densities and groves as scatterCell (so the far canopy has the near forest's glades). weights are the biome weights there.
Only tall species (6 m and up) count; a crown is taken as 0.6 of the height across.
packages/terrain/src/scatter.ts:82
castShadow function
function castShadow(relief: Relief, x: number, y: number, z: number, sun: V3, reach = 3000, hardness = 24, step0 = 0.5): numberSoft shadow of the relief at a point: march along the ray to the sun, and track how close the ray passes over the ground relative to its distance. 1 = fully shadowed. The step grows with distance (fine near, coarse far), so a mountain far away still shades a valley.
packages/terrain/src/chunks.ts:15
cells function
function cells(u: number, v: number, p: number, seed: number, fn: (dx: number, dy: number, cx: number, cy: number) => void, jitter = 1): voidthe cells of a p x p jittered grid that wraps: calls fn for the 3 x 3 cells round (u, v) with the offset to the cell's point (in cell units) and the cell's wrapped index
packages/terrain/src/ground-sets.ts:41
centroid function
function centroid(m: SolidMesh): V3the centre of mass of the closed solid (uniform density)
packages/terrain/src/ice.ts:79
chunkId function
function chunkId: (k: ChunkKey) => stringpackages/terrain/src/chunks.ts:44
clamp function
function clamp: (x: number, a?: number, b?: number) => numberpackages/terrain/src/noise.ts:14
clearDayLight function
function clearDayLight(): { sunColor: V3; ambient: V3; exposure: number }packages/terrain/src/tone.ts:72
distantSpecies function
function distantSpecies(species: Species[], o: { density: number; size?: number; variants?: number }): Species[]The species of a far ring from the game's: the tall ones this module draws as far trees, density times as many of them (a share, 0..1) and size times as large (the crowns of the thinner forest read from far off), with variants shapes each. The cover of the forest is what the near species give times density * size^2.
packages/terrain/src/distant.ts:65
erodeCorrection function
function erodeCorrection(below: Below, o: { step: number; block: number; border: number; iterations: number; strength: number; talus: number }, key: string): LatticeCorrectionpackages/terrain/src/erosion.ts:112
erodeGrid function
function erodeGrid(h0: Float32Array, nx: number, ny: number, p: ErodeParams): Float32ArrayStream-power erosion on a filled surface plus thermal creep; returns the new heights. Deterministic: no random numbers, fixed order.
packages/terrain/src/erosion.ts:51
fbm function
function fbm(x: number, z: number, seed: number, o: FbmOptions = {}): numberfractal gradient noise, about -1..1 (normalised by the sum of amplitudes, so the range does not depend on the octave count)
packages/terrain/src/noise.ts:67
fillDepressions function
function fillDepressions(h: Float32Array, nx: number, ny: number, eps = 1e-3): Float32ArrayPriority-flood: raises every pit to the level at which it spills over its lowest rim; the region's edge is an outlet. eps keeps the filled surface draining.
packages/terrain/src/erosion.ts:33
filmic function
function filmic(c: V3, exposure: number): V3the curve in numbers, as the shaders apply it: linear light to the linear 0..1 picture colour; exposure 0 or less leaves it
packages/terrain/src/tone.ts:48
floatation function
function floatation(m: SolidMesh, rhoBody = ICE_DENSITY, rhoWater = SEAWATER_DENSITY): FloatationHow a solid of ice floats: the waterline where the displaced water weighs as much as the ice, the centres of mass and buoyancy and the metacentric height. The mesh is in its own frame (y up); it must be closed. A berg floats with ~90 % of its volume under water, which is what waterline and draught give.
packages/terrain/src/ice.ts:69
flowSpeed function
function flowSpeed(relief: Relief, x: number, z: number): numberthe speed of the water at a point of a river, m/s (zero outside the water)
packages/terrain/src/water.ts:45
gradient function
function gradient(x: number, z: number, seed: number, out: Noise2 = OUT): Noise2Gradient noise with analytic derivatives, -0.71..0.71. Writes into out (default: a shared object, so read it before the next call). The gradient at each lattice point is a unit vector at a hashed angle.
packages/terrain/src/noise.ts:44
grassCell function
function grassCell(ground: Ground, x0: number, z0: number, size: number, o: GrassCellOptions = {}): GrassClump[]The grass clumps of the square cell [x0, x0 + size) x [z0, z0 + size), sorted by rank. Deterministic: the clumps sit on a world lattice jittered by seed, so neighbouring cells meet exactly and a cell is the same whenever and in whatever order it is asked for.
packages/terrain/src/grass-view.ts:92
grassClumpMesh function
function grassClumpMesh(blades: number, seed = 1): { positions: Float32Array; blade: Float32Array; indices: Uint32Array }the clump mesh: blades strips of five rows each, feet in a unit disc, facing every way, of 0.5..1 of the clump's height
packages/terrain/src/grass-view.ts:279
hash2 function
function hash2(ix: number, iz: number, seed: number): numberuniform 0..1 from a lattice point
packages/terrain/src/noise.ts:22
hash3 function
function hash3(ix: number, iy: number, iz: number, seed: number): numberpackages/terrain/src/noise.ts:28
icebergField function
function icebergField(seed: number, x0: number, z0: number, size: number, o: { density: number; minSize: number; maxSize: number; exponent?: number; tabularShare?: number }): { x: number; z: number; size: number; kind: 'tabular' | 'domed'; seed: number }[]A field of bergs by the size law: many small, few large. Positions are inside the square, deterministic from the seed.
packages/terrain/src/ice.ts:151
lakeCorrection function
function lakeCorrection(below: Below, o: { step: number; block: number; border: number; minDepth: number }, key: string): LatticeCorrectionLakes: pits deeper than minDepth are filled flat to their spill level.
packages/terrain/src/erosion.ts:118
layersIn function
function layersIn(ground: Ground, x0: number, z0: number, size: number, o: { grid?: number; min?: number } = {}): string[]the layers that cover a square of the ground (sampled on a grid), heaviest first, those under min of the samples left out
packages/terrain/src/ground-textures.ts:32
leafMaskPixels function
function leafMaskPixels(side = 128): Uint8Arraya card's leaflets: small pointed ovals fanned along the card (u from the stalk to the tip, v across), inside its diamond; deterministic
packages/terrain/src/scatter-view.ts:86
lighterShape function
function lighterShape(d: MeshData, k: number): MeshDataa lighter copy of a shape: every k-th triangle on its own vertices, enlarged about its centre by sqrt(k) * 0.85 (cards and needles keep the crown's mass)
packages/terrain/src/scatter-view.ts:49
loadKPa function
function loadKPa: (mass: number, area: number) => numberthe load of a walker's foot or a wheel, kPa: weight (kg) over the contact area (m2)
packages/terrain/src/memory.ts:127
lookOf function
function lookOf(layer: string, extra?: Record<string, LayerLook>): LayerLookpackages/terrain/src/palette.ts:24
makeIceberg function
function makeIceberg(o: IcebergOptions): SolidMeshAn iceberg as a closed solid, above and below the water: a lofted body whose outline is a noisy ellipse; the tabular one has a flat top and steep, slightly undercut sides with a flat bottom, the domed one a rounded top with pinnacles and a long keel. The y axis is up and the origin is the middle of the body.
packages/terrain/src/ice.ts:122
makePoly function
function makePoly(pts: Vec2[]): Polypackages/terrain/src/relief.ts:15
makeRock function
function makeRock(seed: number, variant: number, angular = 0.7, detail = 3): MeshDataA rock of unit size (its largest dimension is 1, the base is flat on y = 0). angular 0..1: how faceted it is (fresh blocks and boulders) against rounded
(weathered cobbles). Deterministic from (seed, variant).
packages/terrain/src/scatter.ts:126
manning function
function manning(slope: number, hydraulicRadius: number, n = 0.045): numberdischarge from the width and depth with a rough Manning speed
packages/terrain/src/water.ts:11
membership function
function membership(v: number, r: Range, fade = 0.35, min = 1e-6, cap = Infinity): number1 inside the range, falling to 0 over fade of the range width (at least min) outside it
packages/terrain/src/biomes.ts:20
meshVolume function
function meshVolume(m: SolidMesh): numberthe mesh volume by signed tetrahedra against the origin (a closed, outward-wound mesh)
packages/terrain/src/ice.ts:21
meteredExposure function
function meteredExposure(albedo: number, base = 0.5): numberthe exposure a camera meters for ground of this mean albedo (linear; TerrainView.meter): base (default clearDayLight's) is right for grass, soil,
rock and sand (0.15 to 0.4); a snowfield or salt flat gets less, a dark lava field more. Some of the difference (in stops) is left, as cameras and eyes leave it: snow stays
brighter than grass, but it is no longer clipped white
packages/terrain/src/tone.ts:66
mix function
function mix: (a: number, b: number, t: number) => numberpackages/terrain/src/noise.ts:15
nearestOnPoly function
function nearestOnPoly(p: Poly, x: number, z: number, out: PolyHit = { d: 0, t: 0, s: 0 }): PolyHitthe nearest point of a polyline to (x, z)
packages/terrain/src/relief.ts:27
paintGround function
function paintGround(recipe: GroundRecipe, side: number, seed = 1): GroundCanvaspaint a recipe at side pixels (the height, colour and roughness before the maps are made)
packages/terrain/src/ground-sets.ts:295
pfbm function
function pfbm(u: number, v: number, px: number, py: number, octaves: number, seed: number, gain = 0.5): numberfractal sum over the tile (u, v in 0..1): the first octave has px x py cells, each next twice as many; about -1..1
packages/terrain/src/ground-sets.ts:28
pnoise function
function pnoise(x: number, y: number, px: number, py: number, seed: number): numbergradient noise with whole periods px, py (in lattice cells), about -1..1
packages/terrain/src/ground-sets.ts:20
pointAtPoly function
function pointAtPoly(p: Poly, s: number): Vec2the point at distance s along a polyline
packages/terrain/src/relief.ts:21
pridged function
function pridged(u: number, v: number, px: number, py: number, octaves: number, seed: number, gain = 0.5): numbersharp crests where the noise crosses zero, 0..1
packages/terrain/src/ground-sets.ts:34
pworley function
function pworley(u: number, v: number, p: number, seed: number, jitter = 1): typeof Wpackages/terrain/src/ground-sets.ts:51
registerLandscapeCommands function
function registerLandscapeCommands(c: CommandsLike, l: Landscape): voidThe landscape.* commands over a Landscape (the plain JSON in and out the inspector and agents use).
packages/terrain/src/landscape.ts:100
registerSurfaces function
function registerSurfaces(materials: { add(id: string, m: { friction: number; restitution: number; rollingFriction?: number }): unknown }, extra: Record<string, SurfacePhysics> = {}): voidput every surface into a physics material table (host.materials)
packages/terrain/src/physics.ts:22
ridged function
function ridged(x: number, z: number, seed: number, o: FbmOptions & { sharpness?: number } = {}): numberridge lines, 0..1 (1 on the ridge); multifractal so the ridges are rougher where the earlier octaves were high
packages/terrain/src/noise.ts:81
riverProfile function
function riverProfile(relief: Relief, line: number, step = 2): RiverPoint[]The profile of river index (of relief.riverLines()): every step metres along the line the bed, the surface, the width and the flow speed. The surface never rises downstream (water does not flow uphill): where the bed climbs, the level is held at the lowest seen so far.
packages/terrain/src/water.ts:17
rockfall function
function rockfall(relief: Relief, x0: number, z0: number, v0: [number, number, number] = [0, 0, 0], o: RockfallOptions = {}): RockPoint[]A boulder let go at (x, z) with an optional start velocity: it falls under gravity, bounces off the ground by the restitution along the ground normal, rolls with rolling resistance and stops when it can no longer move. Fixed step, no random numbers.
packages/terrain/src/hazards.ts:66
rockfallSource function
function rockfallSource(relief: Relief, x: number, z: number, o: { rock?: number } = {}): numberwhere on the slopes above a point boulders could come from: cells steeper than the angle of repose with bare rock, as 0..1
packages/terrain/src/hazards.ts:95
runout function
function runout(path: SlidePoint[]): { length: number; maxSpeed: number; end: V3 }the runout of a slide: how far it went and how fast it was at its fastest
packages/terrain/src/hazards.ts:54
scatterCell function
function scatterCell(ground: Ground, species: Species[], x0: number, z0: number, size: number, seed = ground.relief.seed, grid = 9): Instance[]Everything of the given species standing in the square cell [x0, x0 + size) x [z0, z0 + size).
packages/terrain/src/scatter.ts:40
settle function
function settle(m: SolidMesh, seed = 1): { rotation: Mat3; mesh: SolidMesh; floating: Floatation }The orientation a berg rolls to: of a set of trial orientations (the six faces up and a seeded spread), the one with the lowest potential energy of the floating body, m g (zG - zB) measured above the waterline's centre of buoyancy. Returns the rotation, the rotated mesh and its floatation.
packages/terrain/src/ice.ts:96
setWaterRings function
function setWaterRings(m: BABYLON.ShaderMaterial, rings: { readonly packed: Float32Array; readonly max: number } | undefined, scene: BABYLON.Scene): voidthe ring sources of a water response map into a water shader's ringData (zeros when it has none), and the size of a pixel at a metre for its band limit
packages/terrain/src/view.ts:217
slide function
function slide(relief: Relief, x0: number, z0: number, o: SlideOptions = {}): SlidePoint[]A slide of snow or debris from a start point: the Voellmy-Salm model along the line of steepest descent (with a little inertia, so it can run through a bend and over a rise). dv/dt = g (sin t - mu cos t) - g v^2 / (xi h). Stops when the speed is gone. Returns the path with the speed along it.
packages/terrain/src/hazards.ts:34
smootherstep function
function smootherstep: (a: number, b: number, x: number) => number0 below a, 1 above b, quintic in between (zero first and second derivatives at both ends)
packages/terrain/src/noise.ts:18
smoothstep function
function smoothstep: (a: number, b: number, x: number) => numberpackages/terrain/src/noise.ts:16
subSeed function
function subSeed: (seed: number, n: number) => numbera seed for the n-th use of a base seed (octaves, layers, species): well mixed, never equal for different n
packages/terrain/src/noise.ts:35
surfaceMaterialId function
function surfaceMaterialId: (surface: string) => stringpackages/terrain/src/physics.ts:19
toTerrain function
function toTerrain(ground: Ground, o: ToTerrainOptions): TerrainA physics-terrain Terrain over a region of the ground: the surface follows the relief and each column is the biome's soil over rock.
packages/terrain/src/physics.ts:39
unfilmic function
function unfilmic(c: V3, exposure: number): V3the linear light that the curve turns into the picture colour c (linear 0..1, each channel below about 0.97 so it stays finite); exposure 0: c
packages/terrain/src/tone.ts:54
validateSpec function
function validateSpec(spec: unknown): Issue[]every problem of a spec, with the path of the place; an empty list means the spec can be built
packages/terrain/src/spec.ts:185
voronoi function
function voronoi(x: number, z: number, seed: number, jitter = 1, out: Cell = { f1: 0, f2: 0, id: 0, cx: 0, cz: 0 }): Cellcellular noise: distances to the nearest and the second nearest feature point (cells of side 1; jitter 0..1), the id 0..1 and the point of the nearest cell
packages/terrain/src/noise.ts:110
warp function
function warp(x: number, z: number, seed: number, amplitude: number, wavelength: number, octaves = 3, out: [number, number] = [0, 0]): [number, number]domain warp: the point moved by (fbm, fbm) * amplitude; wavelength in metres. Returns the moved point in out.
packages/terrain/src/noise.ts:124
waterfalls function
function waterfalls(profile: RiverPoint[], o: { minDrop?: number; maxRun?: number; depth?: number } = {}): Waterfall[]The waterfalls of a profile: runs of the surface that drop more than minDrop metres over at most maxRun metres.
packages/terrain/src/water.ts:33
Interfaces
BiomeDef interface
interface BiomeDefid: string | |
name: string | |
manual?: boolean | only where the author puts it (a biome zone), never picked by the climate rules: farmland, volcanic fields |
climate: BiomeRange | |
blend: number | metres over which this biome blends into its neighbours |
relief?: import('./spec').ReliefOp[] | operations this biome adds to the relief inside its area (a mountain biome adds ridged noise and erosion, a steppe almost nothing) |
layers: LayerRule[] | |
soil: string | physics-terrain soil id, physics material id |
surface: string | |
weather: { dustiness: number; looseSnow: number; soilWetness: number } | what the biome gives the weather: dustiness, looseSnow, soilWetness as |
air?: { haze: number; tint?: V3; sky?: boolean } | air: haze multiplies the level's fog density; sky: false is no atmosphere (the lunar biome: black sky, hard light) |
gravity?: number | gravity in m/s2 for a whole biome that is a different world (the Moon 1.62, Mars 3.71); the level's gravity otherwise |
packages/terrain/src/types.ts:55
BiomeInput interface
interface BiomeInputtemperature: number | |
moisture: number | |
height: number | |
slope: number |
packages/terrain/src/biomes.ts:29
BiomeRange interface
interface BiomeRangethe climate a biome lives in, and where on the ground it can be (the rule table of T3 picks by these; the biome map overrides it)
packages/terrain/src/types.ts:46
Brush interface
interface Brushx: number | |
z: number | |
radius: number | |
strength: number | |
mode?: 'raise' | 'lower' | 'smooth' | 'flatten' | |
height?: number | |
falloff?: number |
packages/terrain/src/landscape.ts:13
BuildOptions interface
interface BuildOptionscanopy?: CanopyFn | |
sun?: V3 | |
shadowReach?: number | |
shadowHardness?: number | |
cells?: number | |
skirt?: number | |
looks?: Record<string, LayerLook> | |
ground?: Ground | |
paint?: (x: number, z: number, h: number, slope: number, rgb: V3) => V3 | [number, number, number, number] | |
splat?: Record<string, number> |
packages/terrain/src/chunks.ts:151
Cell interface
interface Cellf1: number | |
f2: number | |
id: number | |
cx: number | |
cz: number |
packages/terrain/src/noise.ts:108
Chunk interface
interface Chunk extends ChunkKeyx0: number | |
z0: number | |
size: number | |
id: string |
packages/terrain/src/chunks.ts:29
ChunkKey interface
interface ChunkKeylevel: number | |
ix: number | |
iz: number |
packages/terrain/src/chunks.ts:28
ChunkMesh interface
interface ChunkMeshchunk: Chunk | |
positions: Float32Array | metres relative to (x0, 0, z0); (n + 1)^2 grid vertices then 4 (n + 1) skirt vertices |
normals: Float32Array | |
colors: Float32Array | per vertex: colour (rgb 0..1) baked from the layers, and a 4th value: the layer's grain 0..1 for the fragment detail |
morph: Float32Array | per vertex: how far (m) it moves down to the coarse surface when fully morphed; 0 on even vertices |
shadow: Float32Array | per vertex: 0 in the sun .. 1 in the shadow of the ground (cast shadows by marching towards the sun), when a sun was given; otherwise all zero |
indices: Uint32Array | |
splat?: Float32Array | when built with splat: per vertex the weights (summing to at most 1) of the chunk's four main layers, and which texture slot each of the four is (-1: none) |
slots?: [number, number, number, number] | |
min: number | lowest and highest point, for culling bounds |
max: number | |
n: number |
packages/terrain/src/chunks.ts:97
ClimateSample interface
interface ClimateSampletemperature: number | |
moisture: number | |
exposure: number |
packages/terrain/src/climate.ts:24
ClimateSpec interface
interface ClimateSpectemperature?: number | annual mean temperature at sea level at the origin, Celsius (default 12) |
lapse?: number | cooling with height, Celsius per km (default 6.5) |
gradient?: { direction: number; perKm: number } | a latitude-like gradient: Celsius per km along direction degrees (0 = +x, 90 = +z); default none |
moisture?: number | base moisture 0..1 (default 0.5), a noise that makes wet and dry regions, and how far wet air carries from the sea (metres of height above it) |
moistureNoise?: { amplitude: number; wavelength: number } | |
wind?: number | the wind the weather comes with, degrees it blows towards; high ground upwind dries the lee (rain shadow) |
rainShadow?: number | |
fixed?: { temperature?: number; moisture?: number } | fix a quantity to a constant everywhere (an arctic level: temperature -20, moisture 0.1) |
seed?: number |
packages/terrain/src/climate.ts:6
CollisionOptions interface
interface CollisionOptionstile?: number | the tile edge, metres (default 32) and its cell (default 0.5; a power of two keeps tiles on the lattice) |
cell?: number | |
radius?: number | tiles within this distance of a tracked body are kept (default 1.5 tiles) |
budget?: number | tiles built per update (default 2) |
material?: string | physics material for the tiles, by the surface id; one material for all unless the kernel supports per-triangle materials |
packages/terrain/src/physics.ts:54
ErodeOp interface
interface ErodeOp extends OpBasewears the ground built so far: rain carves valleys that drain downhill, steep slopes creep to their talus angle. Computed on world-aligned lattice blocks, so it stays a pure function of (seed, x, z).
op: 'erode' | |
step?: number | lattice step, metres (default 8); finer detail below it is kept untouched |
iterations?: number | rounds of carving and creep (default 12; fewer rounds cut harder, so the total stays the same) |
strength?: number | 0..2, how hard the water cuts (default 1) |
talus?: number | the slope the creep keeps, degrees (default 38) |
block?: number | block size in lattice cells (default 96) and the overlap that hides the seams (default 24) |
border?: number |
packages/terrain/src/spec.ts:118
ErodeParams interface
interface ErodeParamsiterations: number | |
strength: number | |
talus: number | |
step: number |
packages/terrain/src/erosion.ts:48
FallMesh interface
interface FallMeshpositions: Float32Array | |
uv: Float32Array | |
indices: Uint32Array |
packages/terrain/src/water-mesh.ts:75
FbmOptions interface
interface FbmOptionsoctaves?: number | |
lacunarity?: number | |
gain?: number | |
damp?: number | 0 = plain fbm; 1 = octaves are divided by 1 + |accumulated slope|^2 (erosion-like) |
packages/terrain/src/noise.ts:59
Floatation interface
interface Floatationvolume: number | |
mass: number | |
waterline: number | the waterline height in the mesh's own frame, metres, and the draught below it |
draught: number | |
freeboard: number | |
centreOfMass: V3 | |
centreOfBuoyancy: V3 | |
gm: number | metacentric height GM, metres: positive is stable. The tilt axis giving the least GM is the one used. |
submergedVolume: number |
packages/terrain/src/ice.ts:10
GrassCellOptions interface
interface GrassCellOptionslooks?: Record<string, GrassLook> | grass per layer, over GRASS_LOOKS |
density?: number | clumps per square metre where a layer's density is 1 (default 16) |
grid?: number | the spacing of the ground queries in a cell, metres (default 4; the layers are blended between them) |
groundLooks?: Record<string, LayerLook> | the ground's own colours by layer (GroundTextures.looks() when the land is textured): far blades turn to them; default LAYER_LOOK |
sun?: V3 | direction towards the sun: the relief's cast shadow is found per clump, as the terrain bakes it (none without) |
shadowReach?: number | how far the shadow rays reach, metres (default 3000) |
seed?: number | a seed of the grass's own, added to the ground's |
packages/terrain/src/grass-view.ts:51
GrassClump interface
interface GrassClumpone clump: its foot on the ground, size, the blades' colours, its rank (0..1: the farther the camera, the fewer ranks are drawn) and the shadow on it
x: number | |
y: number | |
z: number | |
yaw: number | |
height: number | height of the tallest blade and the radius the blades stand in, metres |
radius: number | |
width: number | blade width at the foot, metres |
rank: number | |
color: V3 | living colour and dry colour (sRGB), the part of dry blades, the droop |
dryColor: V3 | |
dry: number | |
bend: number | |
ground: V3 | the ground's colour here (sRGB), which far blades turn to |
shadow: number | 0 in the sun .. 1 in the relief's shadow |
packages/terrain/src/grass-view.ts:69
GrassFlowMap interface
interface GrassFlowMapwhat the grass reads of a local flow map (FlowMap of
readonly size: number | |
readonly cell: number | |
readonly originX: number | |
readonly originZ: number | |
readonly data: Float32Array | |
readonly active: boolean | |
readonly version: number |
packages/terrain/src/grass-view.ts:168
GrassLook interface
interface GrassLookhow one ground layer grows grass: none (rock, sand, snow) unless listed
density: number | clumps where this layer is all of the ground, as a part of the full density (0..1) |
height: [number, number] | the height of a clump's tallest blade, metres, from .. to |
width: number | a blade's width at its foot, metres |
color?: V3 | the living blade's mean colour (sRGB 0..1); default the layer's ground colour |
dry: number | the part of the blades that are dead straw (0..1) and their colour (default a pale straw) |
dryColor?: V3 | |
bend: number | how far the blades droop under their own weight (0 stiff upright .. 1 arched over) |
packages/terrain/src/grass-view.ts:18
GrassViewOptions interface
interface GrassViewOptions extends GrassCellOptionsground: Ground | |
radius?: number | how far the grass reaches (default 32 m) and how far it is at full density (default 7 m); between, it thins and turns to the ground's colour |
near?: number | |
cell?: number | cell edge, metres (default 8); cells built per update and the milliseconds they may take (default 4 and 4) |
cellsPerUpdate?: number | |
buildMs?: number | |
blades?: number | blades in a clump (default 16) |
textures?: GroundTextures | the land's textures: far blades take their colours (GroundTextures.looks()) |
sunColor?: V3 | the light, as the terrain's (TerrainViewOptions): direction towards the sun, its colour, the sky's, haze colour and density per metre |
ambient?: V3 | |
haze?: V3 | |
hazeDensity?: number | |
exposure?: number | the tone curve's exposure and the sun's shadow map, as the terrain's (TerrainViewOptions.exposure, sunShadow): the grass is shaded by the plants' shadows and toned like the land |
sunShadow?: SunShadow | |
shadows?: boolean | cast shadows of the relief on the grass (default true when there is a sun) |
wind?: () => { dir: [number, number]; speed: number; time: number } | the wind now (as ScatterViewOptions.wind): direction in x, z (unit), speed at 10 m in m/s, time in seconds |
flowMap?: GrassFlowMap | local air on top of the wind (propeller and fan wash, jets): a grid of horizontal velocities round a centre; the blades near a source lie down and shiver. Absent: the grass is drawn exactly as without it. |
packages/terrain/src/grass-view.ts:145
GrassViewStats interface
interface GrassViewStatscells: number | |
pending: number | |
clumps: number | |
blades: number | |
builtThisUpdate: number |
packages/terrain/src/grass-view.ts:170
GroundCanvas interface
interface GroundCanvasside: number | |
h: Float32Array | |
c: Float32Array | |
r: Float32Array | |
seed: number |
packages/terrain/src/ground-sets.ts:61
GroundImageSource interface
interface GroundImageSourcewhere the images come from: AssetLibrary.image of
image(setId: string, channel: GroundChannel): Promise<CanvasImageSource> |
packages/terrain/src/ground-textures.ts:15
GroundMaps interface
interface GroundMapsside: number | |
basecolor: Uint8Array | RGBA, sRGB |
normal: Uint8Array | RGB, tangent space, +Y up (glTF) |
orm: Uint8Array | RGB: occlusion, roughness, metal (glTF) |
height: Uint8Array | one channel, 0..255 over the recipe's relief |
packages/terrain/src/ground-sets.ts:268
GroundOptions interface
interface GroundOptionsspec: Pick<TerrainSpec, 'seed' | 'relief'> & { seaLevel?: number } | |
climate?: ClimateSpec | |
biomes?: BiomeDef[] | the biomes; default are the shipped ones |
zones?: BiomeZone[] | the author's biome map |
packages/terrain/src/ground.ts:13
GroundRecipe interface
interface GroundRecipeid: string | |
name: string | |
tags: string[] | |
metres: number | metres of ground one repeat covers |
relief: number | metres of relief between height 0 and 1 (the normal map's strength) |
ao?: number | how strongly hollows darken (ambient occlusion) |
pixel(u: number, v: number, o: Px, seed: number): void |
packages/terrain/src/ground-sets.ts:72
GroundSample interface
interface GroundSampleWhat the ground is at one place; the one answer that rendering, collision, physics, weather, sound and AI all ask (implemented in T3 and T8).
height: number | metres, the relief height |
normal: V3 | unit normal, y up |
slope: number | rise over run |
biome: string | the dominant biome id and every biome's weight (they sum to 1) |
weights: Record<string, number> | |
layer: string | the dominant paint layer (grass, sand, rock, snow, ice, regolith...) |
soil: string | the physics-terrain soil id and the physics material id of the dominant layer |
surface: string | |
wetness: number | 0..1 how wet the ground is (swamp 1, desert 0) |
water: { level: number; kind: 'sea' | 'lake' | 'river' | 'pool' } | null | the water surface above this point, or null on dry land |
packages/terrain/src/types.ts:8
GroundTexturesOptions interface
interface GroundTexturesOptionslayers: string[] | the layers to draw with textures (see layersIn); at most MAX_SETS distinct sets |
side?: number | texture side in pixels (1024 desktop, 512 mobile) |
tint?: number | 0: the photograph's own colour; 1: its mean pulled exactly onto the layer's palette colour (default 0.7) |
looks?: Record<string, LayerLook> | |
sets?: Record<string, LayerSet> | a layer's set other than LAYER_SET's |
packages/terrain/src/ground-textures.ts:16
IcebergOptions interface
interface IcebergOptionskind: 'tabular' | 'domed' | |
size: number | the longest horizontal dimension, metres |
aspect?: number | height of the whole body as a fraction of size (tabular 0.12 .. 0.25, domed 0.35 .. 0.6) |
seed?: number | |
detail?: number | rings of detail (default 24 segments by 14 rings) |
packages/terrain/src/ice.ts:107
ImportOp interface
interface ImportOp extends OpBaseop: 'import' | |
origin: Vec2 | |
step: number | |
nx: number | |
ny: number | |
heights: number[] | nx * ny metres, rows along z |
edge?: number | metres over which the grid's edge fades into the ground built so far |
packages/terrain/src/spec.ts:105
Instance interface
interface Instancespecies: string | |
variant: number | |
x: number | |
y: number | |
z: number | |
yaw: number | |
tilt: [number, number] | |
scale: number | |
layer: string |
packages/terrain/src/scatter.ts:34
Issue interface
interface Issuepath: string | |
message: string |
packages/terrain/src/spec.ts:175
LakeOp interface
interface LakeOp extends OpBasefills every pit deeper than minDepth flat to the level where it spills over, so basins become lakes (the water itself comes with the water module)
op: 'lake' | |
minDepth: number | |
step?: number | |
block?: number | |
border?: number |
packages/terrain/src/spec.ts:134
LandscapeOptions interface
interface LandscapeOptionsspec: TerrainSpec | |
climate?: ClimateSpec | |
zones?: BiomeZone[] | |
biomes?: BiomeDef[] |
packages/terrain/src/landscape.ts:11
LayerLook interface
interface LayerLookcolor: V3 | |
rough: number | |
grain: number |
packages/terrain/src/palette.ts:6
LayerRule interface
interface LayerRulea ground layer a biome paints, and the conditions it takes over where they hold (the weights then blend and sum to 1)
layer: string | a material id of the asset library, or the id of a procedural ground material of this module |
weight: number | base weight |
slope?: Range | |
height?: Range | |
wetness?: Range | |
noise?: { wavelength: number; lo: number; hi: number; seed?: number } | a noise that breaks up the layer's patches: smoothstep(lo, hi) of fbm at this wavelength (metres) |
packages/terrain/src/types.ts:33
LayerSet interface
interface LayerSeta layer's near texture: the library set and the metres one repeat covers
set: string | |
metres: number |
packages/terrain/src/ground-sets.ts:247
MemoryOptions interface
interface MemoryOptionscell?: number | cell of the buffer, metres (default 0.05: 5 cm resolves a boot) |
tile?: number | tile edge in cells (default 64) |
floor?: number | smaller dents than this are dropped, metres (default 0.0005) |
packages/terrain/src/memory.ts:31
MeshData interface
interface MeshDatapositions: Float32Array | |
normals: Float32Array | |
indices: Uint32Array | |
colors?: Float32Array | |
uvs?: Float32Array | card coordinates per vertex (2 each): u along a leaf card, v across it; negative on solid parts. The plant shader cuts leaf outlines out of the cards |
packages/terrain/src/scatter.ts:100
Noise2 interface
interface Noise2v: number | |
dx: number | |
dz: number |
packages/terrain/src/noise.ts:37
NoiseOp interface
interface NoiseOp extends OpBaseop: 'noise' | |
kind: 'fbm' | 'ridged' | 'billow' | 'voronoi' | fbm: -1..1 hills; ridged: 0..1 ridge lines (mountains); billow: 0..1 rounded humps; voronoi: cells or cracks |
amplitude: number | metres of height at the noise value 1 |
wavelength: number | metres of the first octave's feature size |
octaves?: number | |
lacunarity?: number | |
gain?: number | |
damp?: number | fbm only: 0..1+, smooth the steep ground and keep detail on the flat (erosion-like) |
sharpness?: number | ridged only: 1 soft .. 4 knife edges |
cell?: 'cells' | 'edges' | voronoi only: cells is f1 (domes), edges is f2 - f1 (cracks, polygons, terraces) |
offset?: number | added to the noise value before the amplitude (fbm and billow centre ~0 / ~0.5) |
warp?: WarpSpec |
packages/terrain/src/spec.ts:29
PaintOp interface
interface PaintOp extends OpBaseop: 'paint' | |
size: number | the lattice: size metres per stored tile, n samples per tile edge (step = size / n); the stored value is metres added |
n: number | |
tiles: Record<string, number[]> | only the edited tiles are stored: key "ti,tj" -> n * n values, row-major (z rows) |
packages/terrain/src/spec.ts:96
PlannerOptions interface
interface PlannerOptionscell: number | the finest cell, metres (10 cm underfoot for a walking game, 20 m for a flight sim) |
cells?: number | cells along a chunk's edge (default 32; power of two) |
levels: number | quadtree levels above the finest: the coarsest chunk is cell cells 2^levels metres wide |
split?: number | a chunk is split while the camera is nearer than split times its size (default 1.5) |
radius: number | draw distance, metres: chunks farther than this are not planned |
packages/terrain/src/chunks.ts:31
PlantMesh interface
interface PlantMesh extends MeshDatacolors: Float32Array |
packages/terrain/src/plants.ts:11
Poly interface
interface Polypts: Vec2[] | |
cum: number[] | |
length: number |
packages/terrain/src/relief.ts:14
PolyHit interface
interface PolyHitd: number | |
t: number | |
s: number |
packages/terrain/src/relief.ts:13
PondOp interface
interface PondOp extends OpBaseA pond or a lake you place: a bowl cut into the ground round center and filled with water to a level that is the ground's own height at the centre minus drop.
Unlike lake (which finds the pits that are there, block by block, so cannot see a pit wider than its block) it is exact and cheap at any size, so it is the way to put
a lake of kilometres into a plain of a hundred. The shore is made irregular by a noise on the distance.
op: 'pond' | |
center: Vec2 | |
radius: number | the radius of the water at its level, metres |
depth?: number | how deep the bowl goes under the level at the centre, metres (default 14) |
drop?: number | how far under the ground at the centre the water stands, metres (default 1.5) |
ragged?: number | 0..0.5, how ragged the shore is (default 0.24) |
packages/terrain/src/spec.ts:147
PrintsViewOptions interface
interface PrintsViewOptionscell?: number | cell of the patch, metres (default 0.15) |
n?: number | cells along an edge (default 64) |
tint?: [number, number, number] | colour of a print at its darkest, linear-ish 0..1 (default a damp brown) |
packages/terrain/src/prints-view.ts:6
Px interface
interface Pxwhat a recipe's pixel function writes: height 0..1, colour (sRGB 0..1), roughness 0..1
h: number | |
r: number | |
g: number | |
b: number | |
rough: number |
packages/terrain/src/ground-sets.ts:63
RiverHit interface
interface RiverHitd: number | |
half: number | |
t: number | |
s: number | |
op: number | |
cx?: number | |
cz?: number |
packages/terrain/src/relief.ts:295
RiverOp interface
interface RiverOp extends OpBaseop: 'river' | |
points: Vec2[] | |
width: number | water-surface width at the start and the end of the line, metres (grows along the line) |
widthEnd?: number | |
depth: number | |
bank?: number | bank slope width each side, metres |
meander?: number | sideways wander, metres, wavelength metres |
meanderWavelength?: number |
packages/terrain/src/spec.ts:82
RiverPoint interface
interface RiverPoints: number | |
x: number | |
z: number | |
bed: number | |
level: number | |
width: number | |
speed: number | |
slope: number |
packages/terrain/src/water.ts:7
RockfallOptions interface
interface RockfallOptionsradius?: number | |
restitution?: number | |
rolling?: number | |
dt?: number | |
maxTime?: number | |
rest?: number |
packages/terrain/src/hazards.ts:59
RockPoint interface
interface RockPointt: number | |
x: number | |
y: number | |
z: number | |
speed: number | |
airborne: boolean |
packages/terrain/src/hazards.ts:60
ScatterViewOptions interface
interface ScatterViewOptionsground: Ground | |
species: Species[] | |
cell?: number | the cell edge, metres (default 64) and how far cells are kept (default 4 cells) |
radius?: number | |
cellsPerUpdate?: number | cells built per update (default 1) |
tint?: [number, number, number] | a rock colour tint over the layer's colour, and how bright they are (a dark basalt boulder on a bright regolith) |
generators?: Record<string, (seed: number, variant: number) => MeshData> | a generator of the game's own for shapes this module does not draw: returns mesh data of unit size, base at y = 0 |
sun?: [number, number, number] | the light, as the terrain's (TerrainViewOptions): direction towards the sun, its colour, the sky's, the haze colour and density per metre. With sun
the plants get their own shader (lit and hazed like the land, swaying in the wind); without it they keep a standard material lit by the scene's lights |
sunColor?: [number, number, number] | |
ambient?: [number, number, number] | |
haze?: [number, number, number] | |
hazeDensity?: number | |
wind?: () => { dir: [number, number]; speed: number; time: number } | the wind now (from the game's weather): direction in x, z (unit), speed at 10 m in m/s, time in seconds; plants lean and sway by it, gusts travel downwind |
exposure?: number | the tone curve's exposure, as the terrain's (TerrainViewOptions.exposure); the haze is then the colour the far air shows |
sunShadow?: SunShadow | a SunShadow the plants and stones cast into (swaying with the wind as they are drawn) and are shaded by, with the ground that reads it |
lodDistance?: number | beyond this distance (metres, measured to the cell's centre; default 0 = off) a cell draws a lighter copy of every plant: one triangle in lodKeep (default 4)
kept and enlarged about its centre, so the crown stays full and the triangle count falls. The foot and the stones keep their shape |
lodKeep?: number | |
leafCut?: number | leaf cards show their leaflets (cut out by a mask) out to this distance, metres (default 45); beyond, the whole card is drawn |
keepOut?: (x: number, z: number) => boolean | where nothing of the scatter stands (a level of the game's own lies there with its own plants): an instance at x, z for which it says true is left out |
innerBand?: [number, number] | a ring: plants dissolve in (a dither) between these two distances from the camera, metres, and cells wholly inside the first are not built; a view with this stands out beyond a nearer one that dissolves out over the same band (default none) |
biomeGrid?: number | nodes per side of the grid the biome weights of a cell are read on (default 9; a far ring of big cells needs 3: the weights change slowly and each node costs a millisecond) |
fadeIn?: number | seconds a cell takes to dissolve in (a dither, from its build): what streams in after the first frame never shows as a jump (default 1.5) |
packages/terrain/src/scatter-view.ts:11
SlideOptions interface
interface SlideOptionsmu?: number | friction coefficient (dry flowing snow 0.15-0.3, wet 0.35-0.5) and the turbulent drag (Voellmy xi, m/s2; 400-2000) |
xi?: number | |
depth?: number | flow depth, metres (0.5-3) |
speed?: number | the start speed and a step, metres |
step?: number | |
maxLength?: number |
packages/terrain/src/hazards.ts:21
SlidePoint interface
interface SlidePointx: number | |
y: number | |
z: number | |
speed: number | |
s: number |
packages/terrain/src/hazards.ts:19
Softness interface
interface Softnesssink: number | metres a 1 kPa load sinks the surface; 0 for ground that does not take a print |
rim: number | the share of the sunk volume that is pushed up at the rim, 0..1 |
heal: number | per second, the fraction of the dent that heals (sand slumps, snow fills, mud keeps its shape, rock has none) |
max: number | deepest the surface can be pressed, metres |
packages/terrain/src/memory.ts:8
SolidMesh interface
interface SolidMeshpositions: Float32Array | |
indices: Uint32Array |
packages/terrain/src/ice.ts:9
Species interface
interface Speciesid: string | |
shape: string | what it is drawn as: a generator of this module (rock, boulder, tuft, tree-conifer, tree-broadleaf, shrub, reed, cactus, dead-tree) or model:<library id> |
biomes: Record<string, number> | individuals per 100 m2 where a biome of weight 1 lists this species: biome id -> density |
size: Range | metres, the largest dimension, and the exponent of the size law: many small, few large (the number larger than s falls as s^-exponent; default 2) |
exponent?: number | |
layers?: Record<string, number> | ground layers that favour it (layer id -> multiplier on the density where the layer is dominant), others count 1 |
slope?: Range | |
height?: Range | |
wetness?: Range | |
cluster?: { wavelength: number; lo: number; hi: number } | clumping: a noise (wavelength m) the density is multiplied by smoothstep(lo, hi) of, so they gather in patches |
buried?: number | the fraction of its height sunk into the ground (rocks 0.3, trees 0) |
variants?: number | how many different shapes the generator makes of it |
dry?: boolean | stays away from open water |
wades?: number | the deepest water (m) it stands in, over any lake, river or sea of the relief (default 0.15: plants and trees do not grow in water; reeds and water plants say more) |
packages/terrain/src/scatter.ts:8
SunShadowOptions interface
interface SunShadowOptionssun: V3 | direction towards the sun |
radius?: number | half the side of the square the map covers, metres (default 60); and how far ahead of the camera its centre goes, a share of that (default 0.55) |
ahead?: number | |
size?: number | texels on a side (default 4096) |
depth?: number | the depth the map spans along the sun, metres: everything that may cast into the square must lie in it (default 600) |
strength?: number | how dark the shadow is, 0..1 (default 1: the sun is all gone, the sky still lights it) |
packages/terrain/src/sun-shadow.ts:10
SurfacePhysics interface
interface SurfacePhysicsfriction: number | |
restitution: number | |
rolling: number |
packages/terrain/src/physics.ts:10
TerraceOp interface
interface TerraceOp extends OpBaseop: 'terrace' | |
steps: number | |
sharpness?: number | 0 soft .. 1 hard treads |
from: number | the height band that is terraced, metres |
to: number |
packages/terrain/src/spec.ts:72
TerrainSpec interface
interface TerrainSpecversion: 1 | |
seed: number | the seed of everything; a different seed is a different world |
size?: number | the biggest extent that matters, metres (the root of the chunk tree); default 65536 |
cell?: number | the finest cell the view builds, metres; default 4 |
seaLevel?: number | sea level in metres of relief height; default 0 |
relief: ReliefOp[] |
packages/terrain/src/spec.ts:162
TerrainViewOptions interface
interface TerrainViewOptions extends PlannerOptionsground: Ground | |
buildsPerUpdate?: number | at most this many chunk builds in one update, and at most this many milliseconds (default 2 and 4) |
buildMs?: number | |
sun?: V3 | the sun direction (towards the sun) and light colours; haze colour and density per metre |
sunColor?: V3 | |
ambient?: V3 | |
haze?: V3 | |
hazeDensity?: number | |
looks?: Record<string, LayerLook> | |
paint?: (x: number, z: number, h: number, slope: number, rgb: V3) => V3 | [number, number, number, number] | the game's own colour of the ground at a vertex, after the layers' (see BuildOptions.paint) |
shadows?: boolean | bake the cast shadows of the relief for the sun direction above (costs build time; setSun rebakes when the sun moves) |
material?: (scene: BABYLON.Scene) => BABYLON.Material | a material of the game's own instead of the built-in shader (it gets the same attributes: position, normal, color, morph, and uv = world x, z in metres for detail textures) |
water?: boolean | 'inland' | draw the water (sea, lakes, rivers) as sheets; 'inland' leaves the sea to a surface of the game's own (waves, ships) and draws only lakes and rivers with depth colour, fresnel sky reflection, sun glints and ripples that follow the river's flow (default true) |
receiveShadows?: number | chunks this size (m) and smaller receive the scene's shadow maps (a game material with a shadow generator); default none |
waterColors?: { shallow?: V3; deep?: V3; sky?: V3 } | colours of the water: shallow, deep (linear 0..1) and the sky it reflects; defaults suit a temperate sea |
textures?: GroundTextures | the ground sets of the layers (GroundTextures.load): the built-in shader then draws each layer with its textures near the camera, and the far
colours of those layers become the sets' tinted mean colours so the two agree |
detailFar?: number | how far (m) the textures are drawn before they give way to the colour (default 3000) and how strongly their normals lean the light (default 1) |
normalGain?: number | |
exposure?: number | the filmic tone curve (ACES) with this exposure over the linear light (the sun and sky colours may then go above 1, as a sunny day's do); the haze
colour stays the colour the far air shows on the picture. Without it the light is only gamma-encoded. Give the plants (ScatterView) the same |
sunShadow?: SunShadow | shadows of the things near the camera (trees, plants, stones) on the ground, from a SunShadow they cast into |
canopy?: { species: Species[]; from: number; /** metres over which the crowns come in beyond `from` (default 0.4 of it) */ ramp?: number } | the trees beyond the plants' reach: from from metres (the ScatterView's radius less a cell) out, growing to full over a further 40%, the ground
draws the crowns of species (the ScatterView's list, in the same order) as a lifted layer canopy, with the near forest's groves and glades. Put
canopy in the textures' layers to give it its texture. A chunk keeps what it was built with until the view replaces it |
packages/terrain/src/view.ts:16
TerrainViewStats interface
interface TerrainViewStatschunks: number | |
pending: number | |
triangles: number | |
drawCalls: number | |
builtThisUpdate: number | |
levels: number[] |
packages/terrain/src/view.ts:52
TileOptions interface
interface TileOptionsx0: number | world x, z of the tile's corner; snapped to the lattice (a multiple of size / n) so that neighbouring tiles of one level share their edge exactly |
z0: number | |
size: number | edge length, m |
n: number | cells per edge (vertices: n + 1) |
border?: number | extra rings of samples around the tile, for normals and for operations that look sideways; default 1 |
packages/terrain/src/relief.ts:362
ToTerrainOptions interface
interface ToTerrainOptionsx0: number | |
z0: number | |
size: number | edge of the square region and the column size, metres |
cell: number | |
soils?: SoilLibrary | |
top?: number | the loose layer's thickness over bedrock (default 1.5 m) and how deep the bedrock reaches below the lowest point (default 8 m) |
depth?: number | |
waterTable?: number | ((x: number, z: number) => number) | |
soilFor?: (soil: string) => string | map a biome's soil name to one this library has (default: names that are missing become silt) |
packages/terrain/src/physics.ts:26
WarpSpec interface
interface WarpSpecamplitude: number | |
wavelength: number | |
octaves?: number |
packages/terrain/src/spec.ts:27
Waterfall interface
interface Waterfallx: number | |
z: number | |
height: number | |
run: number | |
width: number | |
discharge: number | |
s: number |
packages/terrain/src/water.ts:8
WaterMesh interface
interface WaterMeshchunk: Chunk | |
positions: Float32Array | metres relative to (x0, 0, z0) |
depth: Float32Array | per vertex: how deep the water is here, metres (0 at the shore; a dry corner is negative) |
flow: Float32Array | per vertex: the flow in m/s along x and z (zero for lakes and the sea) |
indices: Uint32Array | |
kind: Float32Array | 0 sea, 1 lake, 2 river per vertex, so a look can differ |
min: number | |
max: number |
packages/terrain/src/water-mesh.ts:9
Types
Below type
type Below = (x: number, z: number) => numberthe ground before this operation at (x, z)
packages/terrain/src/erosion.ts:8
BiomeZone type
type BiomeZone = { biome: string; feather?: number } & ({ center: Vec2; radius: number } | { polygon: Vec2[] })where the author says which biome it is: a circle or a polygon with a feathered edge; zones listed later win
packages/terrain/src/biomes.ts:27
Blend type
type Blend = 'add' | 'max' | 'min' | 'set' | 'mul'packages/terrain/src/spec.ts:14
CanopyFn type
type CanopyFn = (x: number, z: number) => { cover: number; height: number }the trees' crowns at a place for a far chunk (BuildOptions.canopy): the share of the ground they cover and their height, metres
packages/terrain/src/chunks.ts:149
GroundChannel type
type GroundChannel = 'basecolor' | 'normal' | 'orm' | 'height'packages/terrain/src/ground-textures.ts:13
Mask type
type Mask = | { kind: 'radial'; center: Vec2; inner: number; outer: number; invert?: boolean } // 1 within `inner` metres, fading to 0 at `outer` | { kind: 'noise'; wavelength: number; seed?: number; lo: number; hi: number; invert?: boolean } // smoothstep(lo, hi) of fbm mapped to 0..1 | { kind: 'height'; lo: number; hi: number; invert?: boolean } // of the ground built so far (lo > hi: low ground) | { kind: 'line'; points: Vec2[]; inner: number; outer: number; invert?: boolean }where an operation acts, 0..1 (1 = fully); several masks multiply
packages/terrain/src/spec.ts:8
Mat3 type
type Mat3 = [number, number, number, number, number, number, number, number, number]packages/terrain/src/ice.ts:88
PlantMaker type
type PlantMaker = (seed: number, variant: number) => PlantMeshpackages/terrain/src/plants.ts:527
Range type
type Range = [number, number]A range [lo, hi] a rule applies within; a value outside fades to 0 over fade of the range's width.
packages/terrain/src/types.ts:30
ReliefOp type
type ReliefOp = NoiseOp | ShapeOp | TerraceOp | RiverOp | PaintOp | ImportOp | ErodeOp | LakeOp | PondOppackages/terrain/src/spec.ts:160
ShapeOp type
type ShapeOp = OpBase & { op: 'shape' } & ShapeSpecpackages/terrain/src/spec.ts:70
ShapeSpec type
type ShapeSpec = | { shape: 'massif'; center: Vec2; radius: number; height: number; profile?: number; ruggedness?: number } | { shape: 'range'; points: Vec2[]; width: number; height: number; ruggedness?: number } | { shape: 'crater'; center: Vec2; radius: number; depth: number; rim?: number; rimWidth?: number; ejecta?: number } /** a field of craters by a size-frequency law: many small, few large; deterministic by cell, so any region can be built alone */ | { shape: 'craters'; minRadius: number; maxRadius: number; probability?: number; slope?: number; depthRatio?: number; degrade?: number } /** a valley cut along a line: `v` is river-cut (narrow floor, straight walls), `u` is glacier-cut (flat floor, steep walls); the floor deepens downstream */ | { shape: 'valley'; points: Vec2[]; width: number; depth: number; kind?: 'v' | 'u'; wander?: number } /** a cleft or ravine: a narrow crack with rough walls that tapers out at both ends; width is the opening at the top */ | { shape: 'rift'; points: Vec2[]; width: number; depth: number; roughness?: number } /** a field of sea-ice floes: plates `size` metres across (a Voronoi tessellation) standing `freeboard` above the water, split by leads of open water `lead` wide, with pressure ridges where they meet; `coverage` is the share of plates present (the rest is open water) */ | { shape: 'floes'; size: number; lead?: number; freeboard?: number; coverage?: number } /** crevasse fields on ice: cracks across the flow `direction` (degrees the ice moves towards), `spacing` apart, in patches where the ice bends */ | { shape: 'crevasses'; direction: number; spacing: number; width: number; depth: number; coverage?: number } | { shape: 'volcano'; center: Vec2; radius: number; height: number; calderaRadius: number; calderaDepth: number } | { shape: 'mesa'; center: Vec2; radius: number; height: number; cliff?: number } /** a dune field: `transverse` ridges across the wind with a steep lee face (default), `linear` ridges along it, `barchan` crescents and `star` pyramids scattered over the sand; `wind` is the direction it blows towards, degrees (0 = +x, 90 = +z, as in @ferret/weather) */ | { shape: 'dunes'; kind?: 'transverse' | 'linear' | 'barchan' | 'star'; wind: number; wavelength: number; height: number; slipFace?: number; sinuosity?: number; coverage?: number }packages/terrain/src/spec.ts:51
V3 type
type V3 = [number, number, number]packages/terrain/src/types.ts:5
Vec2 type
type Vec2 = [number, number]packages/terrain/src/spec.ts:5
WaterSource type
type WaterSource = (x: number, z: number) => { level: number; kind: 'lake' | 'river'; flow?: [number, number] } | nullwater a game adds to a relief (Relief.addWater): the surface level at x, z, its kind and, for a river, the flow in m/s along x and z; null where it has none
packages/terrain/src/relief.ts:397
Constants
BIOMES const
const BIOMES: BiomeDef[]packages/terrain/src/biomes-data.ts:12
distantShapes const
const distantShapes: Record<string, (seed: number, variant: number) => MeshData>generators for the shapes of the tall species of this module's forests, of unit height with the base at y = 0 (ScatterViewOptions.generators)
packages/terrain/src/distant.ts:53
FALL_FRAG const
const FALL_FRAG: "\nprecision highp float;\nvarying vec3 vW; varying vec2 vU;\nuniform vec3 cameraPosition; uniform vec3 hazeColor; uniform float hazeDensity; uniform float time;\nfloat h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\nfloat vn(vec2 p) { vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f); return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0. …packages/terrain/src/view.ts:232
FALL_VERT const
const FALL_VERT: "\nprecision highp float;\nattribute vec3 position; attribute vec2 uv;\nuniform mat4 world; uniform mat4 worldViewProjection;\nvarying vec3 vW; varying vec2 vU;\nvoid main() { vec4 w = world * vec4(position, 1.0); vW = w.xyz; vU = uv; gl_Position = worldViewProjection * vec4(position, 1.0); }"packages/terrain/src/view.ts:226
FILMIC_GLSL const
const FILMIC_GLSL: "\nvec3 rrtOdt(vec3 v) { vec3 a = v * (v + 0.0245786) - 0.000090537; vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081; return a / b; }\nvec3 filmic(vec3 c, float exposure) {\n if (exposure <= 0.0) return c;\n c = mat3(0.59719, 0.07600, 0.02840, 0.35458, 0.90834, 0.13383, 0.04823, 0.01566, 0.83777) * (c * exposure / 0.6);\n c = rrtOdt(c);\n return clamp(mat3(1.60475, -0.10208, -0.00327, -0.53 …GLSL: vec3 filmic(vec3 linear, float exposure) returns the linear 0..1 picture colour (before the sRGB gamma); exposure 0 leaves the colour as it is
packages/terrain/src/tone.ts:22
G const
const G: 9.81packages/terrain/src/hazards.ts:9
GRASS_LOOKS const
const GRASS_LOOKS: Record<string, GrassLook>the grass of the shipped layers (layer names of LAYER_LOOK); a game adds its own or overrides through GrassCellOptions.looks
packages/terrain/src/grass-view.ts:36
GROUND_SETS const
const GROUND_SETS: Record<string, GroundRecipe>every ground set made here, by id (the library item is <id>-textures and the material <id>)
packages/terrain/src/ground-sets.ts:222
ICE_DENSITY const
const ICE_DENSITY: 917packages/terrain/src/ice.ts:7
LAYER_LOOK const
const LAYER_LOOK: Record<string, LayerLook>packages/terrain/src/palette.ts:9
LAYER_SET const
const LAYER_SET: Record<string, LayerSet>for every layer of LAYER_LOOK, the library texture set that draws it near and its metres per repeat: a recipe here, or a photographic set of the
library's ground stage (tools/asset-lib/ground/sheets.json). The colour stays the layer's own: the set gives the detail.
packages/terrain/src/ground-sets.ts:251
MAX_LAYERS const
const MAX_LAYERS: 64packages/terrain/src/ground-textures.ts:29
MAX_SETS const
const MAX_SETS: 16packages/terrain/src/ground-textures.ts:28
PLANT_SPECIES const
const PLANT_SPECIES: Species[]The plants a biome set ships with; sizes in metres of height. Forest biomes are stocked to a closed canopy: mature trees dominate the size law (low exponent, a high smallest size; saplings are the shrub layer), so the summed crown area of a stand is about one and a half times its ground; the clustering only opens a few glades. Open country keeps lone trees and groves.
packages/terrain/src/plants.ts:550
plantGenerators const
const plantGenerators: Record<string, (seed: number, variant: number) => PlantMesh>generators for ScatterView: every plant of this module
packages/terrain/src/plants.ts:567
PLANTS const
const PLANTS: Record<string, PlantMaker>packages/terrain/src/plants.ts:529
ROCKS const
const ROCKS: Species[]The species a biome set ships with: rocks and boulders everywhere they belong. Plants join later in this stage.
packages/terrain/src/scatter.ts:154
ROUGH_DIFFUSE_GLSL const
const ROUGH_DIFFUSE_GLSL: "\nfloat roughDiffuse(vec3 n, vec3 L, vec3 V, float sigma) {\n float s2 = sigma * sigma, A = 1.0 - 0.5 * s2 / (s2 + 0.33), B = 0.45 * s2 / (s2 + 0.09);\n float nl = clamp(dot(n, L), 0.0, 1.0), nv = clamp(dot(n, V), 0.0, 1.0);\n vec3 lp = L - n * dot(n, L), vp = V - n * dot(n, V);\n float cphi = dot(lp, vp) / max(length(lp) * length(vp), 1e-4);\n float sa = sqrt(1.0 - min(nl, nv) * min(nl, nv) …GLSL: float roughDiffuse(vec3 n, vec3 L, vec3 V, float sigma), Oren-Nayar's factor over Lambert for a rough surface (sigma the slope spread in
radians): grass, soil and sand look darker toward the sun and brighter with it behind the eye, as photographs of fields show
packages/terrain/src/tone.ts:11
SEAWATER_DENSITY const
const SEAWATER_DENSITY: 1025packages/terrain/src/ice.ts:7
SOFTNESS const
const SOFTNESS: Record<string, Softness>packages/terrain/src/memory.ts:19
SUN_SHADOW_DEPTH_FRAG const
const SUN_SHADOW_DEPTH_FRAG: "\nprecision highp float;\nvoid main() { gl_FragColor = vec4(gl_FragCoord.z, 0.0, 0.0, 1.0); }"the depth pass of a caster: its vertex shader is the caster's own, this fragment writes the depth seen from the sun
packages/terrain/src/sun-shadow.ts:63
SUN_SHADOW_GLSL const
const SUN_SHADOW_GLSL: "\nuniform sampler2D sunShadowMap; uniform mat4 sunShadowMatrix; uniform vec4 sunShadowParams;\nfloat sunShadow(vec3 w, vec3 n, vec3 L) {\n float texel = sunShadowParams.x, metre = sunShadowParams.y, tw = sunShadowParams.w;\n vec3 nl = n * sign(dot(n, L) + 1e-4);\n float cosl = clamp(dot(nl, L), 0.05, 1.0);\n vec4 p = sunShadowMatrix * vec4(w + nl * tw * 1.2 + L * tw * 0.8, 1.0);\n vec3 q = p …GLSL for a receiver: float sunShadow(vec3 worldPos, vec3 normal, vec3 toSun) is 1 in the sun and 0 in a full shadow; float sunCanopy(vec3 worldPos) is the share of a disc 2.5 m round the point that has a caster above it (under a crown the sky is hidden too) (no // comments: Babylon)
packages/terrain/src/sun-shadow.ts:25
SURFACES const
const SURFACES: Record<string, SurfacePhysics>coefficients of friction and restitution by surface id (the surface of a biome); rolling resistance for balls and wheels
packages/terrain/src/physics.ts:13
TERRAIN_FRAG const
const TERRAIN_FRAG: "\nprecision highp float;\nvarying vec3 vN; varying vec4 vC; varying float vDist; varying vec3 vW; varying float vS;\nuniform vec3 sunDir; uniform vec3 sunColor; uniform vec3 ambient; uniform vec3 hazeColor; uniform float hazeDensity; uniform vec3 cameraPosition; uniform float exposure;\n\nvec3 rrtOdt(vec3 v) { vec3 a = v * (v + 0.0245786) - 0.000090537; vec3 b = v * (0.983729 * v + 0.4329510) + 0 …packages/terrain/src/view.ts:103
TERRAIN_SPLAT_FRAG const
const TERRAIN_SPLAT_FRAG: "\nprecision highp float;\nprecision highp sampler2DArray;\nvarying vec3 vN; varying vec4 vC; varying float vDist; varying vec3 vW; varying float vS; varying vec4 vSp; varying vec4 vSl;\nuniform vec3 sunDir; uniform vec3 sunColor; uniform vec3 ambient; uniform vec3 hazeColor; uniform float hazeDensity; uniform vec3 cameraPosition;\nuniform sampler2DArray albedoArr; uniform sampler2DArray detailArr …the fragment shader: up to four layers from the arrays (no // comments: Babylon splits lines at semicolons)
packages/terrain/src/ground-textures.ts:124
TERRAIN_SPLAT_VERT const
const TERRAIN_SPLAT_VERT: "\nprecision highp float;\nattribute vec3 position; attribute vec3 normal; attribute vec4 color; attribute float morph; attribute float shadow; attribute vec4 splat; attribute vec4 slots;\nuniform mat4 world; uniform mat4 worldViewProjection; uniform vec3 cameraPosition; uniform vec2 morphRange;\nvarying vec3 vN; varying vec4 vC; varying float vDist; varying vec3 vW; varying float vS; varying vec4 …the vertex shader of the textured ground: the plain one plus the layer weights and slots
packages/terrain/src/ground-textures.ts:108
TERRAIN_VERT const
const TERRAIN_VERT: "\nprecision highp float;\nattribute vec3 position; attribute vec3 normal; attribute vec4 color; attribute float morph; attribute float shadow;\nuniform mat4 world; uniform mat4 worldViewProjection; uniform vec3 cameraPosition; uniform vec2 morphRange;\nvarying vec3 vN; varying vec4 vC; varying float vDist; varying vec3 vW; varying float vS;\nvoid main() {\n vec4 w = world * vec4(position, 1.0);\ …the palette is sRGB, so it is converted to linear before the light (no // comments in GLSL strings: Babylon splits lines at semicolons and breaks them)
packages/terrain/src/view.ts:89
W const
const W: { f1: number; f2: number; cx: number; cy: number; dx: number; dy: number; }distances to the nearest and second point of a wrapping cell grid (cell units) and the nearest cell
packages/terrain/src/ground-sets.ts:50
WATER_FRAG const
const WATER_FRAG: stringpackages/terrain/src/view.ts:159
WATER_VERT const
const WATER_VERT: "\nprecision highp float;\nattribute vec3 position; attribute float depth; attribute vec2 flow; attribute float kind;\nuniform mat4 world; uniform mat4 worldViewProjection;\nvarying vec3 vW; varying float vD; varying vec2 vF; varying float vK;\nvoid main() {\n vec4 w = world * vec4(position, 1.0);\n vW = w.xyz; vD = depth; vF = flow; vK = kind;\n gl_Position = worldViewProjection * vec4(positio …packages/terrain/src/view.ts:149