Terrain · interface
TerrainMaterial
Several materials blended across one field, as vertex colour.
Explained in Terrain.
interface TerrainMaterialimport type { TerrainMaterial } from '@driftengine/terrain';In depth
A weight map baked into vertex colour, and that is the idiomatic answer here rather than a
compromise. This engine's colour is vertex data — it is what makes the world one flat-shaded
draw call, and the root README says so where it introduces drawMesh's tint. A splat map read by
a shader would mean a texture bound on every terrain draw and a branch in flatFrag, which Track
D measured at 19.8 KB gzipped for a capability generated into sixteen fragment permutations. This
costs nothing at all at runtime: the blend happens once, where the patch is built.
What that gives up, and it is the honest limit: the blend is only as sharp as the mesh. A material boundary inside a cell is drawn as a gradient across that cell, and a patch drawn at a quarter detail blends four times as coarsely as one at full detail. A consumer who wants a sharp line — a road edge, a cliff base — draws that patch at full detail, which is the same dial the geometry already uses.
The weights are read bilinearly, which is the opposite of how a height is read, and the
contrast is the whole reason both decisions are written down. A height is read as the triangle
because the surface is drawn as triangles and the query has to agree with the picture
(heightfield.ts argues that at length). A weight is not drawn: it decides a vertex colour, and
the vertex is wherever the mesh put it. There is no triangulation to agree with, so the smooth
interpolation is simply the better one — reading a weight map as triangles would put a visible
crease along every cell diagonal for nothing.
Properties
| Name | Type | Description |
|---|---|---|
colorreadonly | ReadonlyVec3 | |
emissivereadonlyoptional | number | Self-illumination, revealed at night. Zero unless a material glows. |
specularreadonlyoptional | number | How sharply this material takes a sun highlight, 0 to 1. |