Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdf78e4f826

README.md

ocean_floor_displace

Raises the seabed's flat grid into terrain: one gradient-noise field over world XZ, written into each vertex's height, with the analytic slope written into its normal.

Runs when the mesh recentres rather than every frame. The terrain is still in the world; only the grid under it moves.

It is a compute pass rather than the surface shader's vertex() hook so that every pass that draws the mesh, and everything that reads its vertex buffer, meets the same displaced geometry.

The normal is the derivative of the noise rather than a difference of neighbouring vertices, so it stays correct where the grid is coarse — which, over a clipmap, is nearly everywhere.

The collision patch

The threads past the mesh write a square patch of the same field into heights as plain metres, row-major with the column along world X and the row along world Z — the layout a heightfield collider indexes. plan[2] gives the patch its world centre, its samples per side and its world span.

It is the same call to the same function that raised the vertices. A second evaluation of the noise, in Luau or in a pass of its own, is a copy free to drift from the one that is drawn, and ground stood on a metre from where it is drawn is worse than ground with no collision at all — nothing reports it.

Bindings

BufferAccessContents
planreadlane 0: xy mesh world origin, z vertex count, w noise period (m). lane 1: amplitude, lacunarity, persistence. lane 2: xy patch centre, z samples per side, w patch span (m).
verticesread_writeThe mesh's vertex buffer, engine 23-word layout.
heightsread_writeThe collision patch, side * side f32 metres.

Dispatch vertexCount + side * side threads.