Voxel worlds have a lovely property: everything is made of stuff. The mountain isn't a hollow shell with a nice texture on it. If you want to dig a hole, you dig a hole.
The catch is that stuff takes up space. Make the voxels smaller and the amount of it gets out of hand very quickly, and that, far more than anything to do with looks, is the real difficulty with voxels. Plenty of voxel games and engines already look wonderful. The hard part is the data: storing it, getting it to the GPU, drawing it at a distance, and changing it while someone is standing in it.
My voxels are 5 cm on a side and every one of them can be dug, placed or painted, which makes that problem about as bad as I could make it. Every image here comes straight out of the engine - no paintovers.
Why small voxels are hard
Five centimetres is twenty times finer on each axis than the familiar one-metre block. A single cubic metre of dirt is 8,000 voxels. A blade of grass is one voxel wide. A flower is a few dozen.
My test world is a patch of ground about 200 metres square, which at 5 cm is sixteen million columns before you count a single voxel of height. Give it a few tens of metres of hills and trees and you're into billions of cells. Store them all naively and it simply doesn't fit.
And it all has to stay editable. An edit can't wait for a loading screen or a rebuild of the world. It has to land inside a single frame, without a hitch or a hole appearing in the ground, and it has to look right from eighty metres away as well as up close.
How I attack it
Store as little as possible, and touch only what changes.
- One byte per voxel. Each voxel is an index into a material table. Colour, roughness and whether something glows live in the table, not in the voxel.
- Sparse bricks. The world is cut into bricks of 8 x 8 x 8 voxels, and a brick only exists where there's something in it. Empty sky costs nothing.
- Rays straight into the bricks. There's no mesh standing in for the world. The GPU's ray tracing hardware walks the bricks directly, so what you see is exactly what's stored, down to the last voxel.
- Coarser rings at distance. Up to 50 metres out the world is drawn at the full 5 cm, then at 10 cm to 100 metres, then at 20 cm beyond that. At two hundred metres a 20 cm voxel is about one pixel wide at 1080p, so the detail you give up is detail you couldn't see, and the savings are large.
- Edits rebuild only what they touch. A carve or a placement updates the bricks it overlaps and nothing else. Once the engine is warmed up, a typical click costs its frame two to three milliseconds.
Here's what that adds up to in my current test world, a forest glade generated from a seed:
| Current test world | |
|---|---|
| Bricks at full resolution (5 cm) | about 1.22 million |
| Bricks at 10 cm and 20 cm | about 180,000 and 40,000 |
| Voxel data in system memory | about 760 MB |
| Everything on the GPU (voxels plus ray tracing structures, not counting images) | about 1.4 GB |
| Generation time | about 18 seconds |
About three quarters of those full-resolution bricks are grass and flowers.
The idea behind sparse bricks is old and simple, and it fits in a few lines:
// A sparse voxel world: 8x8x8 bricks, stored only where something exists.
const int B = 8;
sealed class Brick
{
public readonly byte[] Voxels = new byte[B * B * B]; // 512 bytes, 0 = air
}
sealed class World
{
readonly Dictionary<Int3, Brick> bricks = new(); // brick coordinate -> brick
readonly HashSet<Int3> changed = new(); // bricks to upload next frame
public byte Get(Int3 v)
{
var key = FloorDiv(v, B); // which brick holds this voxel
if (!bricks.TryGetValue(key, out var brick)) return 0; // no brick: it is air
var p = v - key * B; // position inside the brick
return brick.Voxels[p.X + B * (p.Y + B * p.Z)];
}
public void Set(Int3 v, byte material)
{
var key = FloorDiv(v, B);
if (!bricks.TryGetValue(key, out var brick))
{
if (material == 0) return; // air into nothing: nothing to do
bricks[key] = brick = new Brick();
}
var p = v - key * B;
brick.Voxels[p.X + B * (p.Y + B * p.Z)] = material;
changed.Add(key); // only this brick goes to the GPU
}
}
Two things fall out of this for free. Empty space costs nothing, because a missing brick means air. And an edit only ever touches the handful of bricks it overlaps, so only those need sending to the GPU. That second one is what lets a carve land within a single frame.
Walking a ray through voxels
Once the ray tracing hardware has worked out which brick a ray enters, something has to walk through the voxels inside it until it hits a solid one. The classic way to do that steps from cell to cell, always crossing whichever cell boundary the ray reaches next. Each step is a couple of comparisons and one addition, which is why it's fast. It's still widely used, decades after it was published.
The light
With the data under control, the fun part: the light is path traced, every frame. Sunlight and a physically based sky land on each surface, bounce around once more, filter through thin leaves, scatter in the air and pick up anything that glows. A real-time budget only buys about one sample per pixel, which on its own is very grainy, so a denoiser from the SVGF family cleans it up, and AgX tone mapping finishes the frame.
The first half of that denoiser is temporal accumulation. The camera barely moves between frames, so most of what a pixel shows this frame it also showed last frame. Work out where this point was on screen a frame ago, fetch what was computed there, and blend in a little of the new sample. Blend enough frames and the noise averages away. The hard part is deciding when the history can be trusted: get it wrong and moving objects drag ghostly trails behind them. The second half, an edge-aware wavelet filter, cleans up whatever the history can't.
What I'm aiming for
A world that looks painterly and alive, and that you can dig into anywhere.
By painterly I mean warm, low sunlight, colour that actually has some saturation in it, shadows filled with blue from the sky instead of falling to black, and air you can see. Alive means grass that moves when the wind picks up and light that changes as the day goes on. Anywhere is the hard part, and it's the data problem again: no surface is scenery, every hill, tree and wall is voxels, and all of them can be carved, built on or painted, with the light correct the moment you do it.
Small voxels mean a lot of data. Path tracing means a lot of work per pixel. Editing means you can't precompute your way out of either. Most of the work so far has been getting all three into one frame at 60 frames a second.
Where it is today
The test world is that forest glade: a flower meadow around a pond, a few lone trees, and a ring of a little over two hundred trees closing it in.
It didn't start out pretty. The first conifers looked like stacks of green dinner plates. The broadleaf crowns were smooth blobs. The meadow was so densely flowered it read as carpet. And the pond, beyond its flat centre, rendered completely black.
A ray gets a fixed number of continuations through transparent material like water and glass - twelve, at the time. Each time a ray passing through the water crossed into a new brick, the water was reported again, and each re-report used up one of those twelve continuations. Deep in the pond they ran out before the ray ever reached the floor, and a ray that finds nothing comes back black. I fixed that one before anything else, since I couldn't judge the lighting of a scene with a black hole in the middle of it.


Light
The sun and the sky are modelled physically, so the colour of the light comes from the model rather than from hand-tuned values. As the sun drops, the light warms up and the shadows stretch out on their own. Thin leaves and blades of grass let light through, so the meadow glows when the sun is behind it.

There's a thin haze in the air, and when the sun sits behind the treeline it catches the light between the crowns.

Anything that glows is a real light. The first lamp I placed glowed nicely and lit nothing around it. Now a lamp lights the grass under it, and it keeps working wherever you put it, including at the bottom of a hole you dug thirty seconds ago.

Water
The pond refracts the floor beneath it, mirrors the trees across from it, and blends the two the way real water does: more mirror at a shallow angle, more window when you look straight down. The cover image of this post is the pond at golden hour, with 5 cm terraces all the way down.
The meadow
Up close, the meadow is blades of grass one voxel wide with flowers standing over them on thin stems. Every one of them is a voxel you can carve, and cutting a stem takes the whole flower with it rather than leaving a head floating in the air.

Building
You can edit the world while it runs. The brush carves, places or paints in a sphere, cube, cylinder or slab, from a single voxel up to two metres across. A ghost outline shows what the next click will do, and undo takes back a whole stroke.

Edits change voxels, not physics. Carve through the bottom of a tree trunk and the crown stays exactly where it was. Falling pieces and flowing water are on the roadmap.

Grass, flowers and leaves sway in the wind, and nothing else does. The ground and the trunks stay perfectly still. I checked: with the wind switched off, two frames rendered seconds apart come out identical to the byte in the normals debug view.
Next
Textured building materials and surfaces that shine are coming, and after them motion: water that flows, pieces that fall when cut loose, weather and creatures.
Performance comes first, though. Right now a frame at 1080p costs around 13 to 17 milliseconds on a high-end desktop GPU, depending on where you stand. The target is 16.6, a steady 60 frames a second, and the forest edge is still over it.
Next time: how I test all this.
Further reading: John Amanatides and Andrew Woo, "A Fast Voxel Traversal Algorithm for Ray Tracing" (1987).


