vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::TerrainChunks Namespace Reference

How a terrain is cut into meshes: square chunks, each at levels that take every vertex, then every second, fourth and eighth, for the cull to pick by distance. More...

Functions

uint32_t perSide (const TerrainAsset &terrain)
 How many chunks terrain is cut into along a side.
MeshAsset build (const TerrainAsset &terrain, uint32_t cx, uint32_t cz, uint32_t level)
 Chunk cx, cz of terrain at level, in the terrain's local space.
uint32_t levelAt (float distance, float chunkWidth)
 The level a chunk takes at distance from the eye.

Variables

constexpr uint32_t CELLS = 32
 Grid squares a chunk spans a side at its finest level.
constexpr uint32_t LEVELS = 4
 Its levels, the k-th taking every 2^k-th vertex.
constexpr float REACH = 1.5f
 Chunk widths from the eye within which a chunk takes its finest level.

Detailed Description

How a terrain is cut into meshes: square chunks, each at levels that take every vertex, then every second, fourth and eighth, for the cull to pick by distance.

Each level hangs a skirt from each rim it shares with another chunk, so where two neighbours meet at different levels the gap between their edges shows the skirt, not the sky. A vertex's uv is the centre of its texel of a map with a texel a grid vertex (the layer weights), so a share painted at a vertex is read there.

Function Documentation

◆ perSide()

uint32_t Vkm::Engine::TerrainChunks::perSide ( const TerrainAsset & terrain)

How many chunks terrain is cut into along a side.

Parameters
terrainA terrain of a valid resolution.
Returns
(resolution - 1) / CELLS.

◆ build()

MeshAsset Vkm::Engine::TerrainChunks::build ( const TerrainAsset & terrain,
uint32_t cx,
uint32_t cz,
uint32_t level )

Chunk cx, cz of terrain at level, in the terrain's local space.

Each grid square is two triangles split along its diagonal from (i, j) to (i + 1, j + 1), as TerrainAsset::heightAt reads them; a coarser level's square is the same over its larger span.

Parameters
terrainIts grid.
cxAlong X, below perSide().
czAlong Z, below perSide().
levelBelow LEVELS.
Returns
The mesh, its bounds set, its skirts among them.

◆ levelAt()

uint32_t Vkm::Engine::TerrainChunks::levelAt ( float distance,
float chunkWidth )

The level a chunk takes at distance from the eye.

Each level holds twice as far as the one before: the finest within REACH chunk widths.

Parameters
distanceMetres from the eye to the chunk's box.
chunkWidthMetres a chunk spans.
Returns
The level, below LEVELS.