Docs / Building a world · v0.120.0

Generating planets

Generating planets

terrain.generatePlanet(id, opts) fills a terrain with a whole world: a sphere of ground with relief, caves, craters and layered materials. The same opts table also works with node:setTerrainGen(opts), which generates a planet the first time a player comes near it. This page covers the layers that make worlds differ from each other: mountain ranges, warped and terraced ground, overhangs, ravines, rivers, and surface materials picked by climate.

Every key is optional, and so is every key inside a layer's table. A planet with none of the layers on this page is the same planet it always was, voxel for voxel.

The relief layers

Key What it makes Keys inside
mountains Ranges of ridged peaks where a slow mask is high height (crest height in metres), scale (ridges across the sphere), sharpness (higher is thinner, steeper crests), coverage (0 to 1, how much of the world has ranges), octaves
warp Bends the relief into folded, wind-carved shapes strength (how far it pushes, as a fraction of the radius), scale
plateau Rounds off every peak above a height into a table top height (metres above the radius), smooth
terrace Steps the ground into terraces, or mesas with plateau step (metres), sharpness (0 is a gentle slope, 1 is a sheer rise)
overhangs Cliffs that lean out over their own foot, and arches depth (how far from the surface the effect reaches), scale (per metre), strength (metres)
ravines Steep-walled cuts with flat floors count, depth, width, length, meander
rivers Rivers that run downhill from the highest ground, each in a valley it carves count, depth, width, seaLevel (where they end, metres above the radius), meander

mountains, warp, plateau and terrace also take latitude = {min, max}, in degrees from the equator, and latitudeEdge, the degrees the layer fades out over past them (5 by default). Both bounds 0 or more mean north and south alike; a negative bound means north is positive, so {-90, -60} is the south pole alone. Latitude is measured round the planet's spin axis, the same one biomes use. Snowy ranges round both poles:

lua
mountains = { height = 60, coverage = 0.8, latitude = {60, 90} },
biomes = { { slot = 12, color = {0.95, 0.97, 1}, latitude = {58, 90} } },

Mountains, warp, plateaus, terraces, ravines and rivers all shape the ground's height in each direction. overhangs is the one that works in three dimensions, so it is the one that can make ground with air under it.

Rivers start at the highest ground and run the way water drains from there: down the slope, and across any basin on the way at the height it fills to, out where it spills, until they reach seaLevel. A river that meets one already traced joins it. On a world with nothing below seaLevel, rivers end at its lowest ground, which is where its lake is. To find where the rivers and ravines went without generating anything, call terrain.planetRivers(opts) with the same opts:

lua
for _, ch in ipairs(terrain.planetRivers(opts)) do
  if ch.river then
    local p = ch.points            -- x1, y1, z1, x2, y2, z2, ... planet-local
    print("a river of " .. #p // 3 .. " points, " .. ch.widths[1] .. " m wide at its source")
  end
end

The points lie on the sphere of the planet's radius; the carved bed is below the ground there.

Which layer made a place

terrain.layersAt(pos) takes a world point over a generated planet and says how much each layer adds to the ground's height in that direction. It reads the generator's own functions, so the shares are the numbers the generator summed, not an estimate:

lua
local l = terrain.layersAt(player.pos)
if l then
  print(string.format("ground %.1f m: base %.1f, mountains %.1f, terraces %.1f, channels %.1f",
    l.height, l.base, l.mountains, l.terraces, l.channels))
  if l.channel then
    print(string.format("%s %d is %.1f m off, %.0f m wide, cutting %.0f%% of its %.0f m",
      l.channel.kind, l.channel.index, l.channel.distance, l.channel.width, l.channel.profile * 100, l.channel.depth))
  end
end
Field Metres of
height The generated ground above the radius: base + mountains + plateau + terraces + channels + craters
base The rolling relief noise (relief, bumpFreq)
mountains The ranges
plateau What rounding off the peaks took away (zero or negative)
terraces What stepping the ground moved it, up or down
channels What rivers and ravines carved (zero or negative)
craters What a crater took away (zero or negative)
overhangs How far the overhang layer moves the surface at the ground there: positive raises it. Not part of height, which is the ground along the direction
warp How far the warp moved the point the relief noise is read at
cell The spacing of the grid the layered ground is worked out on (0 without one)

The ground between grid corners is blended from the corners, and so are the shares. A cut steeper than a cell is spread across one: a ravine's bank falls away over a fifth of its width, so on a world whose cells are about as wide as that, the bank reads as a wall a cell or two across.

channel is the river or ravine whose line passes nearest, on a world that has any: index is its place in terrain.planetRivers with the same opts, kind is "river" or "ravine", width and depth are what it is carved at there, distance is how far the point is from its line, profile is the fraction of its depth the ground at that distance loses (1 on the line, 0 past the bank), and carve is depth × profile, the cut it makes at the point itself. A river's valley reaches four widths from its line; a ravine is full depth to two fifths of its width, then its bank drops to nothing by three fifths.

The answer is the generated ground, before any digging, and nil for a point outside every generated body. It is a debug read: it walks every channel's whole line, about 0.1 ms on a world of a dozen ravines and rivers, so ask it for a few points, not thousands a frame.

Lakes

terrain.planetLakes(opts) answers where water would settle on the same planet, again without generating it. Every basin is filled to the height it spills at, and each connected stretch of water is one lake:

lua
for _, lake in ipairs(terrain.planetLakes(opts, { minDepth = 1 })) do
  print(string.format("a lake at %.1f m, %.0f m across, %.1f m deep", lake.level, lake.reach * 2, lake.depth))
  -- lake.center is planet-local, on the lake's surface: where to put its water.
end

Ground below the rivers' seaLevel is sea, not a lake; pass seaLevel to set it yourself. With no sea at all, the planet's lowest point is where it drains, and it holds no lake. Lakes are found on a grid of cells about cell metres across (3 by default), and only water deeper than minDepth (0.5 m by default) counts.

Both questions cost what working the ground out costs, which on a world of several hundred metres is seconds: too long for a script to wait on. Pass a function last, and the call returns nothing, the work runs off the script thread, and the function gets the answer in a later frame:

lua
terrain.planetLakes(opts, { minDepth = 1 }, function(lakes)
  for _, lake in ipairs(lakes) do placeWater(lake) end
end)
terrain.planetRivers(opts, function(channels) rivers = channels end)

Far ground under water

Ground a long way from the camera is drawn simplified: one vertex for every 2, 4 or 8 voxels. Over a sea floor a few metres down, a simplified vertex can come to rest above the water, and from orbit the seabed shows as dark triangles standing out of the sea. Tell the terrain where its water is and that stops: far ground whose own surface is all under the water is drawn under it.

Most games tell it by declaring the water, which they do anyway. A terrain takes its water from:

  • a Water Volume sea centred on the terrain, or one that is a child of it;
  • a Water Volume pool that is a child of the terrain: flat water over the pool's own footprint;
  • every lake a script declares about the terrain's centre (water.addVolume{ shape = "lake" }): water over that lake's own basin.

A script can set the level itself, which replaces all of those, or turn it off:

lua
terrain.setWaterLevel(1, 805)                    -- a planet: 805 m from its centre
terrain.setWaterLevel(2, 12, { flat = true })    -- flat ground: 12 m up its own +Y
terrain.setWaterLevel(1, 805, { margin = 1, flatten = true })
terrain.setWaterLevel(1)                         -- back to the declared water
terrain.setWaterLevel(1, false)                  -- none: drawn as if it had no water

A level is in the terrain's own frame, so a planet that moves, turns or is drawn at another scale keeps its sea. On a terrain with a Celestial Body a number is a radius, on any other a height; flat says which when that guess is wrong.

What the level changes, and what it leaves alone:

  • Only simplified ground. Ground near the camera is drawn at full detail and never reads the level. Nothing about collision changes either.
  • Only ground that is wholly under water. A simplified vertex stands for a cell of ground. Where every part of that cell's real surface is under the water, a vertex left above it is dropped straight down onto the ground, or held margin metres under the surface where there is no ground beneath it within reach. A cell with any ground above the water is left exactly as it was, so a coast from afar is where the ground puts it, to within one simplified cell.
  • margin (0.25 m) is also the least depth any such vertex is left at. Raise it for a sea with tall waves, or one drawn as a coarse mesh whose flat faces dip under the true sphere.
  • flatten = true draws every wholly submerged cell flat at margin under the surface, whatever depth its floor is at. The default keeps the floor's own depth, which is what water that shades by depth wants to see; flatten suits water clear enough that the simplified floor's facets show through it.
  • A far ball too. A planet far enough to draw as one shaded ball draws it under its sea, when every part of the ground the ball is sampled from is under water.

A level that changes (a tide, a lake declared mid-game) is not applied in the frame it changes: the simplified chunks it reaches are meshed again in the background, a few a frame, each drawing as it was until its new mesh is ready.

A terrain with no water declared on it and no level set is meshed exactly as it always was. Simulated water and heightfields (shape = "sim", "heightfield") set no level on their own, because their surface is not one height: give the terrain a level by hand where one fits.

While a planet's ground arrives

A planet the camera has just been put near draws its ground as it is meshed, nearest first: the ground facing the camera lands in a second or two, and the chunks along its rim many seconds later on a big world. Under what has not arrived, it draws one shaded ball in its ground's colour, so space never shows through it:

  • Near the ground the ball is the body's Occluder, the ball it declares wholly inside itself (occluderRadius), so it never stands out of a valley the player is looking along. A body with no Occluder draws no ball there.
  • From afar the ball grows to the bottom of the planet's ground, read once from its field when it starts streaming. Its silhouette is where the ground's is, within the ground's own height, from the first frame, so a sea, an atmosphere or a ring drawn at the planet's surface meets it at once.
  • In between the ball grows with the camera's height, from 120 m to 480 m above the bottom of the ground, so it never jumps.

The ball is drawn only while ground is still to come. To wait for the finished picture (a screenshot, a probe, a cutscene opening on a planet), read terrain.viewReady(id): the share of the planet's ground in view of the camera that is drawn at the detail it will stay at, which reaches 1 once it is.

lua
-- Hold the cutscene's first shot until the world under it has arrived.
if terrain.viewReady(home) < 1 then return end

Surface materials by climate

biomes is a list of rules. For every patch of surface, the first rule whose ranges all match paints it with that rule's slot and color. A range left out does not constrain. Ground that no rule matches falls back to surfaceA and surfaceB, as before. Deeper layers (subsoil, strata, deep, pockets and seams) are unchanged.

Key Range of
latitude Degrees from the equator, north or south: {70, 90} is the poles
altitude Metres above the radius: {-2, 1} with rivers' seaLevel 0 is a beach band
slope Degrees from level: {40, 90} is cliffs
moisture A moisture pattern from -1 (dry) to 1 (wet); moistureScale sets how large its patches are
nearRiver Within this many metres of a river (a single number)

Order matters, because the first match wins. In the alpine example below, the cliff rule comes before the snow line, so cliff faces stay bare rock even above the snow line.

Blending materials

Each palette slot is its own material. Where two meet, at a biome seam, a painted road, or the rim of a dug pit where the subsoil shows, the terrain crossfades between them. By default the crossfade is one triangle wide, so it is about as wide as a voxel and follows the mesh.

Two settings per slot in the Terrain tab change that:

  • blend, in metres. With a width, the two materials blend over that much ground whatever the voxel size, and the edge runs through the triangles rather than along them. 0 keeps the one-triangle crossfade. Where two slots meet, the wider of their two widths is used.
  • rough, from 0 to 1 (0.5 by default). How much world-space noise breaks up the edge: 0 is a smooth line, 1 wanders by most of the width.

The palette file saves them as suffixes on a slot's line, next to |scale= and |glow:

textures/sand.png|blend=1.5|rough=0.6
textures/gravel.png|blend=1.5

Only ground blends. A layer one voxel under undug ground stays hidden, so the subsoil never shows through the surface above it.

A blend, with its noise, reaches at most 2.5 voxels to each side of the edge, which is 3.75 m on a 1.5 m voxel. A width that would reach further is narrowed to fit: at rough 0.5 that allows about 4.3 m on a 1.5 m voxel. A wider blend also makes the terrain's meshes a little slower to build, up to about 1.6 times at the widest. A palette with no blend widths costs nothing extra.

Border styles

A slot's border can be drawn three ways (|border=), chosen by whichever of the two slots has the wider blend (the lower slot when they are equal):

  • soft (the default): the fade described above.
  • sharp: a crisp line one pixel wide, anti-aliased, for a hand-painted or cel look. |wobble= makes it meander by that many metres of noise, and |wobblesize= sets how wide that noise is (the blend width when left out).
  • pixel: a stepped line on the slot's own texel grid, with no anti-aliasing, for pixel-art ground. For a pixel-art picture (one set to Pixelated), the grid is the picture's own pixels, not the palette's layer size. |dither=, from 0 to 1, breaks the line into a 4×4 dither over that much of the width.

A border with no width still takes its style: a sharp or pixel slot draws a crisp edge halfway across the triangle between the two.

Blending by height

With a height map on a slot (|height=, see Surface maps), |heightblend= from 0 to 1 lets the slots' heights decide which one shows across the border instead of a plain fade. The higher one comes through, so sand fills the cracks between cobbles and grass grows up between stones. The closer to 1, the crisper the patches.

  • |heightbias=, from -1 to 1, pushes a slot up or down, so snow with a bias of 0.3 settles over rock first.
  • |contrast= (1 by default) is how strongly the slot's height map counts. At 0 only the bias does.
  • A slot with no height map counts as half height.
textures/cobbles.png|blend=1|heightblend=0.8|height=textures/cobbles_h.png
textures/sand.png|blend=1|heightblend=0.8|heightbias=-0.2
textures/moss.png|blend=0.5|border=sharp|wobble=0.15
textures/grass_pixel.png|blend=1|border=pixel|dither=0.4

Projects keep their soft borders exactly as they were until a slot sets any of these.

Painting finer than a voxel

A voxel holds one slot, so a texture stroke narrower than a voxel normally fills whole voxels. Turn on Fine paint for a terrain in the Terrain tab's paint settings (or node:setTerrainFinePaint(2) from a script) and each voxel holds 2 or 4 smaller cells a side, so a thin path or a painted stripe keeps its own shape.

  • A dab under half a voxel across paints only the fine cells. It reshapes nothing and costs no remesh.
  • Only blocks you paint fine cost memory: 4 KiB each at 2×, 32 KiB at 4×. terrain.stats().finePaint reports the total.
  • The painted slot's border style draws the stroke's outline: soft fades across one fine cell, sharp is a crisp anti-aliased line with its wobble, and pixel steps on the slot's texel grid with its dither. Blending by height does not apply to a fine outline.
  • Turning it off keeps what was painted fine, saved with the terrain, and draws it whole-voxel. Turning it on again shows it. Switching between 2× and 4× resamples what was painted, and undo does not reverse that.

Hiding a texture's repeat

A ground texture usually repeats every couple of metres, which looks right up close. From 30 m up, though, the repeat shows as a grid. Two more settings per slot in the Terrain tab break it up. Both are off by default, so a palette that doesn't use them looks exactly as it did.

  • antitile, from 0 to 1. Above 0, the texture is laid in hexagons about one tile across. Each hexagon is shifted and turned at random, and blended into its neighbours, so no grid is left. The number is how far a hexagon may turn: 1 turns it any way, which suits moss, sand and rock. Keep it low for textures with a direction, such as strata, planks or tiles. Texel size and filtering stay as they were, including slots set to pixelated. The slot costs three texture reads where it had one.
  • macro, from 0 to 1. A slow swell of lighter and darker patches across the texture, the way real ground varies from far off. 1 brightens or darkens by up to about half. size sets how big the patches are, in metres (60 by default). The pattern is calculated rather than read from a texture, so it costs no texture reads.

They are saved on the slot's line like the others:

textures/moss.png|scale=2.5|antitile=1|macro=0.5|macrosize=80

Texture size and distance

Each palette slot is stored at one size, 256 texels a side unless the project asks for more. Project Settings → Terrain layer size (terrain_layer_size in project.ron) takes 256, 512 or 1024. A bigger layer keeps a photographed ground sharp at the player's feet. Each step takes four times the memory: about 11, 43 and 171 MiB for all 32 layers. The palette is held once on the GPU, shared by the meshed and the raymarched terrain.

How a slot is filtered follows its texture's setting in the Assets panel, the same setting a material's texture honours:

  • Smooth with mipmaps reads smaller, averaged copies of the texture as the ground recedes, with anisotropic filtering at glancing angles. Ground a hundred metres off then shows the texture's average colour instead of shimmering as the camera moves. The copies are averaged in linear light, so a speckled rock keeps its brightness with distance. This is the setting to use for photographed ground.
  • Smooth reads the full-size texture at every distance, as the palette always did.
  • Pixelated reads the nearest texel of the full-size texture, as before. It is the setting a texture has until you change it.

A palette never holds the ground in white while it loads. The frame a palette arrives, every slot shows its own average colour, and its pictures land a few a frame. Each picture is decoded and resized once, then kept in .floptle/cache/palette/ with its average colour, so the next load shows the right colours at once and decodes nothing. The cache belongs to the engine: new projects list .floptle/cache/ in .gitignore, and upgrading a project adds the line. Deleting the folder only makes the next load slower.

Surface maps

A slot can carry the other maps a PBR texture set comes with, so its ground is lit by the sun rather than only coloured. Each is named on the slot's line after its other settings:

textures/rock.png|scale=1.5|normal=textures/rock_normal.png|orm=textures/rock_orm.png|height=textures/rock_height.png
  • normal is a tangent-space normal map in the OpenGL convention (green up the picture), the convention ambientCG, Poly Haven and most other packs ship. The picture lies on level ground with its right toward +x and its top toward −z, as the colour does, so the bumps line up with what you see.
  • orm is the glTF packing: red is occlusion, green roughness, blue metalness. Occlusion darkens the light from the sky and not the sun's. Roughness and metalness multiply the terrain material's own, so they need the material's shading set to Physical to show.
  • height is a greyscale height map. It is loaded with the others and kept for blending slots by height.

Every map is filtered the way the slot's colour is: a slot whose texture is set to Pixelated reads its normal and ORM maps texel by texel too, so each pixel is its own crisp facet, and a small map is enlarged to the layer size without smoothing. Every map follows the slot's scale, its anti-tiling (each hexagon turns its normals with its piece of the picture, so a bump is lit from the same side in every hexagon) and its mipmaps. A slot without maps draws exactly as before and costs nothing; a palette where no slot has any adds no memory at all.

A terrain node's own Material now applies in full: its shading model, roughness and metalness reach the ground. Before this they were ignored and terrain always drew with the Classic model.

A slot's own Material

A palette slot can carry a full Material of its own, the same kind a mesh wears, and then shades with it instead of the terrain's. Wet cobbles beside dry dirt, a glowing lava crack, metal ore in rock, or one unlit slot in a lit world all come from one terrain. What a slot's Material sets:

  • Shading model: Classic or Physical, chosen per slot.
  • Roughness and metalness, multiplied by the slot's ORM map if it has one.
  • Normal strength: how strongly the slot's normal map bends the light. 2 doubles the bumps; a negative value turns bumps into dents.
  • Occlusion strength: how much the ORM map's occlusion darkens the sky's light.
  • Colour: tints the slot's picture.
  • Emissive colour and strength: light the slot gives off, which shows in the dark and is not darkened by occlusion.
  • Unlit: the slot shows its colour as it is, whatever light falls on it.
  • Classic specular, shininess, rim and ambient, for slots shaded with the Classic model.

Where the slot's palette line names no picture or map, the Material's own fill in: its texture becomes the slot's colour, its normal map the slot's normal map, and its roughness, occlusion or metal map the slot's ORM map, read as glTF packs them (R occlusion, G roughness, B metalness). A slot without a Material of its own shades with the terrain's, exactly as before. Where two slots meet, everything above blends across the border with their textures.

A palette with slot Materials is saved in a second file, terrain/<scene>.palette.ron, which holds each slot's line and its Material. The line file is still written beside it with everything it can carry, so an older engine shows the same pictures. A palette without slot Materials keeps the line file alone, byte for byte as before, and taking the last slot Material away removes the second file.

A game reads and sets slot Materials while it runs, with the keys node:setMaterial takes:

lua
-- The lava slot glows brighter as the eruption builds.
local lava = terrain.slotMaterial(4) or {}
lava.emissive = vec3(1, 0.35, 0.05)
lava.emissiveStrength = 2 + 6 * eruption
terrain.setSlotMaterial(4, lava)

-- Rain: the cobbles go glossy, and the dirt slot keeps its terrain's look.
terrain.setSlotMaterial(2, { roughness = 0.15 })
terrain.setSlotMaterial(3, nil)

terrain.setSlotMaterial lays the keys given over the slot's own Material and leaves the rest, and nil gives the slot back to its terrain's Material. Numbers draw on the next frame. A new texture or map path is read in the background into the palette already drawn, so the other slots do not flicker. What a game sets during Play lasts for the run, and Stop puts the palette back as it was.

The shape of what is dug

How dug, raised and sculpted ground is drawn is the project's choice (Project Settings ▸ Terrain shape), and a game can change it while it runs with terrain.setShape:

  • Natural (new projects): curved ground gets as many vertices as its curve needs, each placed on the terrain's own surface. A 3 m dig on 1.5 m voxels is round, with no straight piece of its rim over 0.3 m. Flat ground is never split and costs nothing more.
  • Faceted (projects from before the setting): one vertex a voxel, the crisp low-poly look. A dig is a polygon of voxel-long sides.

Levels 1 to 3 sit between them (terrain.setShape(2)). On a generated world only ground that was dug or raised is subdivided: the world's own relief is drawn as it was, so a planet costs what it did until someone digs. Meshing an edited chunk where the ground curves costs about 1×, 1.1×, 1.9×, 4× and 8× the faceted cost at levels 0 to 4; flat ground is the same at every level.

Example worlds

Each of these is a complete opts table, at a size that generates in a second or two. Change seed for another world of the same kind.

Alpine. Sharp ranges over rolling lowland, snow above 30 m, bare rock on the steep faces, rivers down the valleys.

lua
terrain.generatePlanet(1, {
  seed = 4, radius = 260, voxel = 1.5, relief = 10, caveDepth = 40,
  mountains = { height = 55, scale = 3.2, sharpness = 2.5, coverage = 0.45 },
  rivers = { count = 8, width = 8, depth = 4, seaLevel = -4 },
  biomes = {
    { slot = 3, color = { 0.55, 0.55, 0.58 }, slope = { 38, 90 } },
    { slot = 12, color = { 0.95, 0.96, 1.0 }, altitude = { 30, 999 } },
    { slot = 1, color = { 0.35, 0.55, 0.3 }, nearRiver = 20 },
  },
})

Canyon desert. Warped, terraced red rock cut by deep ravines.

lua
terrain.generatePlanet(1, {
  seed = 9, radius = 260, voxel = 1.5, relief = 14, caveDepth = 30,
  warp = { strength = 0.18, scale = 2.5 },
  terrace = { step = 5, sharpness = 0.85 },
  ravines = { count = 6, depth = 28, width = 18, length = 600, meander = 1.2 },
  surfaceA = { slot = 2, color = { 0.78, 0.45, 0.28 } },
  surfaceB = { slot = 2, color = { 0.86, 0.6, 0.38 } },
})

Archipelago. Ground that falls below a sea level, so the high points stand as islands with sand round them, grey seabed below and green where it is wet.

lua
terrain.generatePlanet(1, {
  seed = 21, radius = 260, voxel = 1.5, relief = 18, caveDepth = 20,
  mountains = { height = 22, scale = 4.5, coverage = 0.5, sharpness = 1.6 },
  rivers = { count = 5, seaLevel = 2 },
  biomes = {
    { slot = 3, color = { 0.42, 0.45, 0.5 }, altitude = { -999, -1 } },
    { slot = 4, color = { 0.92, 0.86, 0.66 }, altitude = { -1, 2.5 } },
    { slot = 1, color = { 0.3, 0.6, 0.32 }, moisture = { -0.2, 1 } },
  },
})

The sea itself is not part of the terrain: place a WaterVolume at the sea level. Centred on the planet, it also keeps the far seabed drawn under the water (see Far ground under water).

Karst arches. Steep overhanging limestone towers on a flat plain.

lua
terrain.generatePlanet(1, {
  seed = 30, radius = 220, voxel = 1.5, relief = 4, caveDepth = 50,
  mountains = { height = 48, scale = 9, sharpness = 5, coverage = 0.65 },
  plateau = { height = 34, smooth = 1.5 },
  overhangs = { depth = 16, scale = 0.07, strength = 7 },
  biomes = { { slot = 3, color = { 0.82, 0.8, 0.74 }, slope = { 30, 90 } } },
})

Salt flats. Flat white pans in the basins, low mesas between them.

lua
terrain.generatePlanet(1, {
  seed = 55, radius = 260, voxel = 1.5, relief = 9, caveDepth = 25,
  plateau = { height = 6, smooth = 4 },
  terrace = { step = 3, sharpness = 0.6 },
  biomes = {
    { slot = 5, color = { 0.96, 0.95, 0.92 }, altitude = { -999, -2 } },
    { slot = 2, color = { 0.7, 0.6, 0.5 }, slope = { 20, 90 } },
  },
})

What it costs

A planet with any of these layers works its ground height out once per direction, on a grid about a voxel across, before it fills a voxel. Each voxel then reads the grid instead of evaluating the layers, so they cost little: a 400 m world with mountains, warp, terraces, overhangs, ravines and rivers generates in about a fifth longer than the same world without them, most of that because mountains give it more surface to fill. Rivers are traced on a coarser copy of the same ground, which is why terrain.planetRivers answers quickly.

What a world holds in memory is its field's chunks, and perf.counts() reports them, every terrain summed, while collection is on. fieldChunks is the chunks holding their voxels at full detail. fieldEdited is the ones written since the world was generated: dug, raised or painted. They are kept, saved and never put away. fieldStandIns is the chunks put away far from the player as coarse stand-ins, made again exactly when something comes near. chunks is a different number: the chunk meshes being drawn. meshesPending is the chunk meshes still to come, those being made (meshesInFlight) and those waiting for a worker; it falls to zero once the ground in view is built.

Leaving the caves for later

From outside, a planet is its surface. Its caves are sealed under at least three voxels of crust, so nothing sees them until a dig breaks in. deferCaves = true takes advantage of that: the generator fills the surface and keeps every chunk that lies wholly in the buried cave zone as plain rock, then makes the real chunk the moment a dig, or any edit, reaches it.

On a 400 m world with an 80 m cave zone that leaves about a quarter of the chunks for later, and the planet fills and keeps about a quarter less. A chunk comes out the same whichever order chunks are made in, so two players' games agree on its caves. It is evened out on its own rather than with its neighbours, so where it meets a chunk the first fill made, its walls can sit a hair (well under a voxel) from where filling the whole planet at once would put them.

A saved field remembers which chunks are still to make; the body's generation spec makes them when it is loaded again.

Small bodies

smallBody makes an asteroid or a comet's nucleus instead of a ball. radius is its size, relief roughens its surface, and it has no cave zone or craters:

lua
terrain.generatePlanet(7, { seed = 12, radius = 30, voxel = 1, relief = 1,
  smallBody = { shape = "binary", elongation = 1.6, lumpiness = 0.4, neck = 0.3 } })
Key What it does
shape "potato": one stretched, lumpy lump. "binary": two lobes joined at a neck, end to end along X. "rubble": a pile of lumps pressed together.
elongation How many times longer than wide, along X (1.5).
lumpiness How lumpy the surface is, 0 to 1 (0.35).
neck A binary's neck, 0 (pinched) to 1 (filled in) (0.35).
lumps How many lumps a rubble pile has (8).

The same seed always makes the same rock. Made far from the player, a rock is coarse stand-ins only; its ground is made exactly as the player comes near. space.belt{ ..., shape = "mixed" } gives every rock in a belt one of the three shapes.

Generator versions

A planet's save holds only the digs and edits made to it. Everything else is made again from its options when it loads, so if a newer engine made ground differently, saved digs would land in different ground. Each change to how the generator makes ground has its own version number, and a world is made by the rules of one version:

Version What changed
0 The first rules.
1 Rivers follow how water drains to the sea. Paint depth is measured under the ground the overhangs leave.
2 A world with caveDepth = 0 has no deep cave rock: its subsoil and strata show.
3 Relief layers take latitude.
4 Ground beside steep relief (ravine walls, terrace risers) is painted and shaped correctly: no untextured patches on ravine walls, no holes along their rims, and raycasts stop at the walls.

generator = 4 in the options picks a version. Without it, a world is made by the project's version, which project.ron holds as terrain_generator. A new project starts at the current version. Upgrading a project sets its version to the one its last engine used, so its worlds come out as they did before. Every save also records the version its ground was made by, and a project can raise its version without moving ground under the digs it has already saved.