Builtin Library
- ..
- README.md1.8 KB
- bindings.yaml898 B
- shader.wgsl5.2 KB
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
| Buffer | Access | Contents |
|---|---|---|
plan | read | lane 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). |
vertices | read_write | The mesh's vertex buffer, engine 23-word layout. |
heights | read_write | The collision patch, side * side f32 metres. |
Dispatch vertexCount + side * side threads.