Journal
Voxels11 min read

Biomes, View Distance and Building

Getting ready for a free Steam demo, the engine went from one hand-made scene to a generated world about 20 km across, with five biomes, kilometres of view distance and proper building tools. All of it built on the foundations that came before.

By James

A sandy desert with dunes and a canyon on the left meets a meadow of red, orange and yellow trees on the right, with a forest of tall floating rock pillars in the distance.

The third video is up.

Recorded live in the engine, exploring and building across the new world.

After the last one, a viewer asked if they could play it, or just get into the world and mess around. The plan is a free demo on Steam, and everything in this entry was done to get the engine ready for it. There's more on what the demo will be at the end.

Up to the last video, everything happened in hand-made scenes: the Glade, with its pond and waterfall, and the Court. They looked good, but they were small, and each one was built all at once when it loaded.

Now there's a world. You pick a seed, it generates, and you can walk or fly in any direction for about 10 km. There are currently five biomes, you can see a few kilometres to the horizon, and you can dig and build on all of it.

This was also the first real test of how the engine is put together. A lot of early decisions were made with something like this in mind: keep the world in small independent pieces, keep the simulation separate from the renderer, make the maths give the same answer on every machine, and put the content in data files instead of code. None of that pays off in a single scene. In a streamed world it either holds up or it doesn't.

It held up, with a few parts that needed real rework.

What carried over

The world is stored as bricks, small blocks of voxels at 5 cm each. The editor, the edit log and the undo system all talk to the world through one interface that hands out bricks. For the Glade, the bricks come from a scene that's built once at the start. For the streamed world, they come from regions that are generated in the background as you move. The editor didn't need to know the difference, so digging, building, painting and undo worked in the new world with very little change.

The split between the simulation and the renderer from the last entry carried over too. The world still only changes on a simulation step, and everything else sends commands. A region that finishes generating gets linked into the world in one step. A dig aimed at ground that hasn't loaded yet gets refused with a reason, the same way a dig outside a scene's bounds already was.

Biomes are a data file. Each one lists its materials, plants, trees, rocks and which animals spawn there, and the generator reads it.

The far view was built before any biomes existed, against a simple interface for "what does the terrain look like here at this level of detail". When the biomes landed, they showed up at distance without any change to the far view code.

And the Glade and the Court are still there. Adding the streamed world didn't change them at all: every test that renders them gave the same image as before, down to the bit. The streamed world sits next to them and shares the same terrain function, tree growth and plants.

What had to change

Plenty, to be fair.

The terrain generator had a few stages that only worked because the whole scene was built at once. One scanned the layout in order, one searched the whole map for where to put floating islands, and the cave grid was anchored to the corner of the scene. In a streamed world each region has to be built on its own, in any order, and still come out the same, so all three had to be rewritten to only look at what's near them.

The GPU side assumed a fixed scene too. Buffers were sized once at the start. They're now pools, with regions taking space when they load and giving it back when they leave, and uploads are spread over several frames so a burst of new terrain doesn't stall a frame.

Positions were the next problem. Floats lose precision the further you get from the origin, and the GPU side used absolute positions that only held up within a few kilometres. The GPU now works relative to a render origin that jumps every 512 m as you travel:

// The GPU only ever sees positions relative to a nearby origin,
// so the numbers it works with stay small wherever you are.
const double Snap = 512.0;

if (Math.Abs(camera.X - origin.X) > Snap || Math.Abs(camera.Z - origin.Z) > Snap)
    origin = new Vector3d(Math.Round(camera.X / Snap) * Snap, 0, Math.Round(camera.Z / Snap) * Snap);

Vector3 ToRender(Vector3d world) => (Vector3)(world - origin);

The simulation, the network, the saves and the streaming never see it. They keep using plain world coordinates, so none of them had to change.

The simulation had to learn that the world has an edge. Water, fire, animals, rain, falling leaves and the sound all run on the regions around the player, about a 5 by 5 block of them. Past that, things are frozen. A region that changed while you were there packs up its state when you leave and gets it back exactly when you return.

Streaming

A region is 64 by 64 brick columns, about 25 m across at full detail. Regions are generated on background threads, four by default, and handed to the main thread when they're done.

The order they're generated in matters more than you'd expect. The obvious approach, nearest first, falls behind as soon as you move, because by the time the nearest regions are done you're somewhere else. So priority is measured from a point a little ahead of where you're going:

// Load the regions nearest to where the player will be soon, not where they are now.
Vector3 ahead = player.Position + player.Velocity * leadSeconds;

float Priority(Region region) =>
    Vector3.Distance(region.Centre, ahead) * LevelWeight(region.Level);

The early measurements are why the world streams instead of being generated up front and loaded from disk. At full detail, one square kilometre of terrain is about 28 GB of GPU memory. No card holds a 20 km world like that, so most of it can never be resident at once, and a map generated up front would still have to be streamed in pieces anyway.

One region took about 25 seconds on one core in the first version of the generator. Spread across the cores it's a few seconds, and after a round of optimising the generator got about three times faster again. That's what decides how fast you can fly before the detail can't keep up. Fast flying now scales with your height, so you can cross the map quickly high up, where the coarse levels are all you need.

Seeing kilometres

Near the player, voxels are 5 cm. Further out the world is drawn at coarser levels, each one with voxels twice the size of the one before, out to 6.4 m voxels at the far end. There are eight levels, and the rings they cover double in size too, so the view reaches about 4.5 km.

A view from a few hundred metres up over a flower-covered valley, with a terraced sandstone mesa, grey highland rock, a dark green forest and floating pillars spreading out to a hazy horizon.
From a few hundred metres up. Everything to the horizon is real terrain at coarser detail.

The coarse levels are generated directly from the same terrain function as the full-detail ground, rather than built by shrinking it down. That's what makes it affordable: a far region at 6.4 m voxels is cheap to generate, and it lines up with what you'll find when you get there. Where two levels meet, the boundary is dithered across a band so you don't see a ring, and grass and flowers thin out with distance and continue as coarse stand-ins. Distant trees are reduced copies of the real trees.

The last part of the view distance fades into the sky so the world doesn't just stop.

Five biomes

BiomeWhat's there
TemperateGlade-like meadows, wooded rises and small ponds. Where you start
HighlandsRidged mountains up to about 160 m, granite and scree, alpine turf, snow on top, sparse conifers
GlowwoodA dark canopy over glowing undergrowth in cyan and violet
Sky islesFloating rock pillars with vines, mist and jungle trees
DesertMesas, canyons and dunes in layered sandstone, with cacti and dead trees

The map is split into cells about 640 m across, each one a biome, with a 64 m band where neighbours blend.

A temperate meadow with autumn trees in the foreground, conifers on a rocky highland slope on the left, a dark glowwood forest on the right and the floating pillars of the sky isles behind it in the haze.
Four of the five from one spot: temperate, highlands, glowwood and the sky isles behind.
Pale desert dunes with scattered shrubs on the left meeting bright green grass and autumn trees on the right, the edge between them broken into soft patches, with floating pillars beyond.
Desert into temperate, with the sky isles behind.

Weather follows the biome. It snows on the peaks, the desert gets dust storms and everywhere else gets rain, blended where you're standing, so walking out of the desert in a storm, the dust thins out around you. A full dust storm cuts visibility to a few hundred metres. Snow sits above a snow line, and plants and animals stay off it.

The same world on every machine

Multiplayer depends on everyone building the same world from the same seed, which I wrote about last time. Streaming makes that harder, because now the world is built in pieces, in whatever order the player happens to move, across however many threads the machine has.

So every region has a hash, and the test is that a region's hash is the same whether it was built alone, next to its neighbours, in a different order, or on a different number of threads. The first version failed that badly, with thousands of bricks coming out differently depending on what had been built before them. That's how the three generator stages above were found. Now it matches every time, on Windows and on Linux.

Trees that cross a region edge were their own problem. A tree's identity comes from a cell in the world, not from the region that happens to be generating it, so a tree that straddles two regions is the same tree in both and doesn't get planted twice. Each region looks at every cell close enough for a tree to reach into it, grows that cell's tree from the cell's own seed, and keeps only the voxels that land inside itself:

// A tree belongs to a cell of the world, not to the region generating it.
foreach (var cell in CellsWithin(region.Bounds, MaxTreeRadius))
{
    ulong seed = Hash(worldSeed, cell.X, cell.Z);
    if (!HasTree(seed)) continue;

    var tree = GrowTree(seed, CellOrigin(cell)); // same seed, same tree, every time
    tree.StampInto(region);                      // only the voxels inside this region
}

Building and the menus

The building tools grew into a proper set: brushes in a sphere, cube, cylinder and slab, plus line, wall, floor, smooth and flatten. Each one shows a ghost preview of exactly which voxels it will change before you click. There's an optional snap grid, paint, an eyedropper, fill and replace, and copy and paste with rotation. Undo and redo are per player, so in multiplayer you only undo your own edits. Everything placeable is in a creative inventory with tabs, and a hotbar holds ten slots.

The engine also has a front end now: a main menu, world creation with a seed you can share, settings for graphics, audio and controls, a pause menu and graphics presets that actually change the cost. There's a built-in benchmark that flies a fixed route and writes out the results. If your card can't do ray tracing, you get a clear message instead of a crash.

A new world is playable in about 40 seconds on my machine. It's waiting on purpose for some of the far terrain to arrive, so you don't spawn into a world with no horizon.

Sound and light, again

After that came a round of refinement by ear and by eye. The first pass at a lot of the sound was rough, so the leaves, grass, fire and birds all got another go: the leaves now come from each tree's crown and rise and fall with the gusts, and the rest are softer and sit better together. None of it is final, and it'll keep getting tuned as the demo gets closer.

Night got a tweak as well. It felt a bit too bright, so the moonlight is dimmer now and the sky darkens more after sunset. It's still not black, which is a fair trade while there's no torch to carry.

Night over a flowering meadow under a starry sky, autumn trees dark red, the floating pillars in silhouette and small points of glowing light among the trees.
Night now, under the stars.

Still open

Water and fire simulations. Both run in the streamed world, but they haven't had the attention and polish I want yet. The mechanics need more work, how water flows and fire spreads both need another pass. So does performance, especially in multiplayer, where a big flowing channel or a forest fire with a few people around it is still the heaviest thing the engine does. And both need better sound. That will be included in the next stretch of work.

The Steam demo

What I'm planning is a free voxel sandbox. No quests, levels or progression, just a world to get into and mess around in. You'd make a world from a seed, alone or with a few friends, and see what you can do with it.

Explore the biomes, build something, or dig out a hillside. Set a forest on fire, flood a valley, carve a cave and light it up, and watch how the world reacts. Multiplayer support is built and runs through Steam already: you host a friends-only or invite-only game, friends join from the menu or an invite.

It's also how I want to find out what people actually do with the engine, to help shape what comes next.

There's no date yet. When there is, I'll let you know here, on YouTube and in our Discord server.