Builtin Library
- ..
- README.md2.2 KB
- bindings.yaml1.6 KB
- shader.wgsl10.4 KB
README.md
terrain_mesh
Builds one quadtree node's vertices from the heightfield's texels, in the engine's 23-word vertex layout, straight into the shared vertex pool the terrain draws from. One thread per node vertex.
Every vertex stands on a stop of the collider's lattice: the field's two edges
and its texel centres along each axis, the stops the terrain's collider holds
its samples at. The node's grid places each vertex, from whole indices counted
from the corner of the rect the cut tiles, and the vertex takes the lattice
stop nearest that place. A node whose vertices are the texel spacing apart or
closer therefore draws exactly the collider's cells, split along the diagonal
from the corner one texel along +Z to the corner one texel along +X, which is
the split the collider and terrainHeightfield.cellHeight make; grid vertices
that land on one stop draw triangles with no area. Along an edge stitched to a
coarser neighbour, the strip of cells next to the edge follows the neighbour's
edge. A coarser node draws a subset of the same lattice.
The height is read from the four texels of the cell around a stop through that same split, and the normal from the gradient the texels carry, blended across them.
Two edge behaviours make an LOD cut renderable:
- Stitching.
coarseMasknames the edges whose neighbour is one level coarser. On such an edge the odd-indexed vertices snap onto the previous even one, so the fine edge becomes the polyline through the coarse neighbour's own vertices. The crack closes because the two edges are then the same line, not because something covers it. - Geomorphing. Over the far end of the distance band a node is a leaf across, every vertex slides onto the position it would hold one level coarser. By the time the cut merges the node into its parent, the node is already drawing the parent's geometry, so the merge moves nothing. The morph runs off each vertex's own distance to the camera rather than the node's, so a vertex two nodes share is placed identically by both.
A vertex is placed from its whole index alone, so every node that holds it, and every child whose vertex morphs onto it, computes the same bits for it and the same lattice stop.