Skip to content
View source

terrainGenerated

Category: Packages · Manifest: use "kernels/";

Ground as heights on a grid of cells.

Ground as heights on a grid of cells: read back as a smooth surface, its normal, where a ray first meets it (crossing blocks it passes over) and how open the sky is over it; worn down by erosion, and laid out as a mesh.

Layer: Graphics. Uses: mesh.

use "terrain.entpkg";
  • kernels/height.ent — Ground as a Grid<Float> of heights, one a cell, the cells cell meters apart; the highest over blocks of cells, for a ray to cross a block it passes over at a step (terrain_hit_over). Kernels: terrain.highest@1.
  • kernels/erosion.ent — Erosion. Kernels: terrain.erode@1.
  • kernels/surface.ent — The ground as a mesh. Kernels: terrain.points@1.

tests/ holds scenes and their replays, run on every backend: ground.replay. Every Kernel of the package is reached by one of them.

Kernel Mode Brief
terrain.erode@1 map One step of thermal erosion: between each cell and its four neighbors, what one stands over the other beyond talus meters slides down by rate (at most 1) of a quarter of it. What a cell gives its neighbor that neighbor takes, so the ground’s sum is kept.
terrain.highest@1 map The highest the ground stands over each block of block by block cells, the cells either side taken in as the heights blended between cells reach them: a roof no place of the block rises past. A node sets domain = ceil(size(heights) / block); terrain_hit_over reads it.
terrain.points@1 map Cell i’s point: its place and height, the ground’s normal there, and its place on the lattice, 0 to 1 across.
Function Brief
terrain_height(h: Grid<Float>, cell: Float, p: Vec2) -> Float The height at p, blended between cells.
terrain_normal(h: Grid<Float>, cell: Float, p: Vec2) -> Vec3 The ground’s normal at p, from the heights a cell either side.
terrain_nonzero(x: Float) -> Float
terrain_span(h: Grid<Float>, cell: Float, from: Vec3, dir: Vec3, low: Float, high: Float) -> Vec2 Where along dir from from the ray is within the ground’s box (across the grid, and from low to high meters up): from x to y, x no less than 0; y below x when it misses the box.
terrain_hit(h: Grid<Float>, cell: Float, from: Vec3, dir: Vec3, low: Float, high: Float) -> Float How far along dir (of unit length) from from the ray first meets the ground, or -1 when it does not within the ground’s box: across the grid, and from low to high meters up.
terrain_hit_over(h: Grid<Float>, cell: Float, highest: Grid<Float>, block: Int, from: Vec3, dir: Vec3, low: Float, high: Float) -> Float Where the ray first meets the ground, as terrain_hit, crossing at a step each block of block cells whose highest (terrain.highest@1) it passes over, or coming down to that roof where it meets it first; under a block’s roof it steps as terrain_hit does.
terrain_open(h: Grid<Float>, cell: Float, p: Vec3, n: Vec3, reach: Float) -> Float How open the sky is over p, whose normal is n, 0.25 to 1: the ground standing above it at twelve places round it, out to reach meters, closes it.
Name Syntax
TerrainMarch struct TerrainMarch { t: Float; last: Float; met: Bool; }

One step of thermal erosion: between each cell and its four neighbors, what one stands over the other beyond talus meters slides down by rate (at most 1) of a quarter of it. What a cell gives its neighbor that neighbor takes, so the ground’s sum is kept.

Mode map
Requires field.read, field.write
Inputs previous: Grid<Float>
Params talus: Float = 0.6, rate: Float = 0.5
Outputs result: Grid<Float>

The highest the ground stands over each block of block by block cells, the cells either side taken in as the heights blended between cells reach them: a roof no place of the block rises past. A node sets domain = ceil(size(heights) / block); terrain_hit_over reads it.

Mode map
Requires field.read, field.write
Inputs heights: Grid<Float>
Params block: Int = 16
Outputs result: Grid<Float>
Source packages/terrain.entpkg/kernels/height.ent

Cell i’s point: its place and height, the ground’s normal there, and its place on the lattice, 0 to 1 across.

Mode map
Requires field.read, field.write
Inputs heights: Grid<Float>
Params cell: Float = 1.0
Outputs result: Rows<MeshPoint>

ground.replay