TL;DR: We wrote our own voxel engine as one C++17 core behind a plain C ABI, with a C# binding and a Unity layer on top. Every look, world and piece of gameplay is a JSON document, so a new world is a new file instead of new code. The same core currently drives six very different worlds in our game Dusk Synth, from a neon city at sunset to a drowned coast. This post walks through the layers, the formats, the worlds, and the measured numbers.
Why Build a Voxel Core at All
Voxel games look simple and are not. A world is made of thousands of chunks, and the cost sits in tight loops over 32,768 voxels at a time: meshing, lighting, terrain generation, saving. That is exactly the code you do not want to write twice, and not the code you want locked inside one engine either.
Three reasons pushed us toward a core of our own:
- One implementation, every target. Two hand-written twins in C# and C++ would double the work and still need test vectors to keep them equal. One C++ core reaches Unity as a native plugin, and the same code can be linked from Unreal, Godot (GDExtension), WebAssembly, or a custom engine. This is the same seam we describe in multi-engine architecture: engine-free logic in the middle, thin adapters at the edge.
- Data first. Every format stores block names, never runtime ids. A save keeps working after the block registry changes, and a world can be diffed, generated, validated, and shared as text.
- A look we could actually tune. Lighting is the main pillar of Dusk Synth. Light has to be a first-class part of the engine (coloured block light, sky light, fog, bloom hooks), not an afterthought bolted onto someone else's meshes.
The core has no third-party dependencies and is not tied to our game. A game is the core plus an engine adapter (rendering, input, physics) plus its own rules.
The Layers
| Layer | What it holds | Why it is separate |
|---|---|---|
| C++17 core | Block registry, palette-compressed 32^3 chunks, greedy meshing with ambient occlusion, raycasts, seeded terrain, region files, chunk streaming, light | The hot loops live in one place and run anywhere |
| C ABI | A flat C99 header over the core | The one stable surface every language and engine can call |
| C# binding | P/Invoke wrappers with IDisposable handles, no engine references |
Gameplay code in a managed language, testable without an editor |
| Pure C# runtimes | The POI runtime and the items runtime, with no engine types and a fixed time step | A server can run the same rules later; tests need no editor |
| Unity layer | Streaming world behaviour, chunk renderer, shaders, style "looks", weather, a demo host | Only this layer knows what a MeshRenderer is |
The Unity layer only reads and reports. It places meshes, draws prompts, and feeds the player's position and input to the runtimes. The rules live below it. That keeps the engine adapter thin, which is the point: other adapters are a matter of writing another thin layer, not another engine. To be clear about status, the core builds and passes its test vectors on desktop and WebAssembly, and the Unity adapter is the one our game runs on. Unreal and Godot adapters are not started.
For how we keep per-frame managed code from stalling these loops, see zero-allocation C# in Unity.
JSON as the Contract
The core and its adapters agree on a small family of versioned JSON documents instead of shared code:
| Format | Use |
|---|---|
voxel-blocks.v1 |
The block registry: shapes, render passes, per-face textures or colour swatches, light emission, opacity, block states |
voxel-volume.v1 |
Prefabs, structures and test levels, with a name palette and run-length, dense or sparse encoding |
voxel-terrain.v1 |
The generator: seed, fractal heightmap, layers, water, caves, canyon carving, terraces, strata, street grids, props |
voxel-style.v1 |
A named look: blocks and terrain inline, plus daylight, light tints, fog, sun, weather, neon, clouds, spawn |
voxel-pois.v1 |
Points of interest: states, interactions, events, enemy waves |
voxel-items.v1 |
Items, recipes, loot tables |
VXW1, VXC1, VXR1 |
Binary world, chunk, and region files (LZ4-compressed regions with checksums) |
MagicaVoxel .vox |
Import and export for hand-made models |
Every importer resolves names through the registry. An unknown block fails the import unless you name a fallback. Because the formats are plain text and schema-checked, the same files are what a backend can host and what a peer could send. A Python oracle re-implements the small portable parts, and golden vectors check that every runtime agrees with it.
Styles Define Whole Worlds
The most useful decision was making a style a complete, self-contained JSON file. It carries the block set, the terrain generator, and the look an adapter applies: sky gradient, sun, fog, weather, neon animation, post-processing. Styles are content, not core. Nothing in the C++ or C# code names a style. Adding a world means writing a file (and, for props, running a seeded generator script), not touching the engine.
Here are the six worlds that currently ship in Dusk Synth. Each screenshot is a raw capture from the player build, at a time of day picked to flatter that world.
Dusk Synth: A City at Sunset
The default world is a flat street grid of towers (12 to 92 voxels tall) in five materials, with 55 percent of the windows lit. The sun is a striped disc that never leaves the end of the avenue. Light does the heavy lifting: an orange key light on sun-facing towers, violet shade, coral haze pooling at street level, cyan glowing road lines, and neon that breathes in slow waves up the buildings while its hue drifts. Rooftop signs, billboards, palms and antennas are props placed by rules from voxel-volume.v1 prefabs. The first image above is this world.
Rural Canyons: Dust, Mesas and Strata
A warm desert day: terraced mesas cut by carve canyons 52 voxels deep, a river at water level, and warped strata that paint red, orange, cream and brown bands on every wall. Towns, barns, windmills and water towers sit on the flats, with hoodoos, arches and buttes in the distance, under drifting dust and voxel clouds. It is the same terrain generator as the city, with different parameters: terracing, ridged-noise carving, and strata replace the street grid.
Sky Islands: Above the Cloud Sea
The terrain is a heightmap under a translucent cloud_sea layer, with a few terraced peaks breaking through. Floating islands use submerge and lift placement rules to hang clear above the sea, with waterfalls, rope bridges, marble ruins and glowing crystals. Trees and ruins land only on the peaks. This is a good example of why placement rules live in data: the same prop system that put palms on a sidewalk puts waterfalls on floating rock.
Sunken Coast: A Drowned City
A low heightmap over water, a sand beach, and half-drowned towers in four architecture styles, aged by a ruin generator that slants crowns, punches holes and adds lean and barnacles. Piers, wrecks, lighthouses, coral and kelp use submerge: "only" and footing rules so they stand on the seabed, while boardwalks and harbour buildings stay on dry land. The big, low sun (8 degrees of elevation) and heavy bloom do the rest.
Frozen Arcology: Neon Warmth in the Snow
A snowbound world of abandoned megastructures: carved valleys floored with ice lakes, ice caves underground, snow-capped pines and firs, comm towers hung with icicles, and stepped arcologies with warm lit windows. Snow falls as cube particles around the viewer, and the sky cycles through a pale low-sun day, dusk, and a green and violet aurora night. This capture is from the aurora hour, where the coloured block light of the windows does the most work.
Jungle Ruins: Temples Under the Canopy
Terraced terrain with river channels carved 16 voxels deep, limestone and jungle-soil strata, and a dense green height fog (heightDensity) that gives the whole valley its depth. Mossy step pyramids up to 57 voxels wide, shrines, colonnades and stone heads are hung with vines, among strangler figs, ferns and palms. Glowing green-yellow embers drift through the air, and at night fireflies and braziers carry the light.
All six styles are colour-only, so they render with no texture art at all; textures by name replace the swatches when they exist. Each style also carries a look.cycle, a day and night cycle of keyframes, so the same world reads very differently at noon, sunset, and midnight.
Streaming, LOD and Lighting
A world is streamed, not loaded. These are the parts that make that cheap.
- Chunks. Cubic 32^3 chunks stored as a palette plus bit-packed indices (0, 1, 2, 4, 8 or 16 bits per voxel). A uniform chunk stores no words at all. Typical terrain is about 7 times smaller than raw 16-bit storage.
- Meshing. A padded 34^3 snapshot is captured on the game thread, then meshed on any thread using 64-bit column masks, so two shifts give every visible face of a column. Greedy merging joins faces of the same block, but only along axes where ambient occlusion does not vary, so a merged quad looks identical to the unmerged ones.
- Light. Sky light plus RGB block light, 4 bits per channel per voxel, spread per channel. Two lamps mix by per-channel maximum, and a fading light keeps its hue. Edits relight incrementally. This is why a magenta lamp and a cyan lamp can wash the same street in two colours.
- Streaming. A streamer decides what is wanted (a cylinder around the viewer, nearest first, with hysteresis), loads from region files or generates on a thread pool, and meshes once all 26 neighbours are present. An async mode bounds game-thread time per update with a millisecond budget, and loads are ordered by view direction so what the camera faces streams in first.
- LOD. Far chunks mesh each 23 or 43 block of voxels as a single cell, with skirts to close seams between neighbouring levels of detail. Rings are set by distance with hysteresis, so chunks do not flicker between levels.
Measured Numbers
These come from the core's own benchmark, run on a desktop Intel i9-9900K under macOS with a radius of 8 chunks and caves on. Single-thread figures are from a quiet machine; the streaming row was measured under load (load average 12 to 20), so it is conservative. Treat them as engine-core numbers on one machine, not a promise for every device.
| Stage | Result |
|---|---|
| World storage | 1,024 chunks (512 stored): 4.6 MB versus 32 MB raw (6.9x smaller) |
| Terrain generation | about 0.55 ms per chunk with caves on one thread, about 0.27 ms with a coarser cave lattice |
| Meshing | about 0.15 ms per chunk on one thread; 512 chunks in about 15 ms on the thread pool |
| Greedy merging | 520k quads versus 1.28M unmerged (2.5x fewer) |
| LOD | 4x fewer quads at lod 2, 13x fewer at lod 4; rings with skirts gave 4.4x fewer overall in the bench |
| Raycast | about 2 microseconds per ray |
| Edits | 10,000 random edits touched 382 chunks, remeshed in about 30 ms |
| Region files | the same 512 chunks: 0.9 MB with LZ4 versus 6 MB uncompressed; save about 60 ms, load about 80 ms |
| Streaming (flying, 60 Hz) | async with a 4 ms budget: game-thread time per update p50 1.4 to 1.7 ms, p95 4.2 to 4.8 ms |
In the Unity demo at the same radius, 1,379 chunks were loaded and 274 drawn. We have not published frame-time numbers for the shipped game yet, because we have not measured them under clean conditions, and we would rather leave the row out than guess.
From Scenery to Gameplay: POIs, Items and Set Pieces
A world that only looks good is a screensaver. The next layer turns the same JSON approach into play.
- Points of interest (
voxel-pois.v1). A POI kind has states, interactions (activate, repair, build, collect, talk, or any verb a game registers), a hold time, a resource cost, and events that fire actions: spawn a wave, show a banner, change the mood, bring in a music layer. The runtime is pure C# with a fixed time step, so it is deterministic and testable without an editor, and a server can run the same rules. - Items (
voxel-items.v1). Item definitions, an inventory and hotbar, weapons (cone, projectile, beam, melee, charge), tools, crafting recipes, and weighted loot tables. The POI system's costs and rewards spend and fill the player's inventory through one interface. - A playable slice. The Dusk Synth style carries its first loop inline: a Radio DJ who sets the scene, a Power Node to repair, shard caches to collect, a Signal Tower to bring back online, and a Build Pad for a Bass Cannon.
The Signal Tower shows the loop best. Players hold the activate button for two seconds, a hit resets the progress, and once it starts the tower enters a defending state. A banner tells them to hold the signal for 45 seconds while sine-wave wisps go after the player and a feedback sapper goes after the tower itself. Survive the timer and the tower goes online: the neon returns, and a bass layer joins the music.
The Build Pad shows how items and POIs meet. Spending 10 Light on a pad builds a Bass Cannon, itself a POI whose single event is a repeating timer that fires at anything in range.
All of that is data. The Bass Cannon is a few lines of JSON: a name, two states, a health value, and a timer event that fires. That is the point of the contract: a designer can add a new POI without a code change.
What Is Next: Experiences
POIs run one place well. A memorable moment needs more: a sequence of steps with objectives, invisible trigger zones, flags and counters that remember what happened, prefabs that appear and vanish on cue, a single named boss spawn, collectible sets, and presentation beats such as camera focus, dialogue and stingers. All of it goes in as additive, optional members of the same voxel-pois.v1 document, run by the same runtime, so existing POIs keep working.
The first part has landed: variables and conditions, trigger zones, sequences with an objective marker on the HUD, tagged spawns, health thresholds, and save and resume. The Dusk Synth loop above, from the Radio DJ to the Signal Tower, now runs as one seven-step sequence. Next are prefabs placed on cue, boss spawns, collectible sets and presentation beats, then reusable encounter templates that let one authored set piece (a neon bridge, a lost-tape hunt, a blackout drop) be placed by rule across worlds.
We will write that up when it ships, with the same rule as this post: only numbers we measured.
References, Standards & Verified Data
- glTF 2.0 Specification: Khronos Group, glTF 2.0 - the right-handed, +Y up, 1 unit coordinate frame the core uses.
- MagicaVoxel
.voxFormat: ephtracy, voxel-model file format - the import and export format for hand-made voxel models. - LZ4 Block Format: Yann Collet, LZ4 Block Format Description - the compression used for region files.
- Sponge Schematic Format: SpongePowered, Schematic Specification - the block order that
voxel-volume.v1follows. - Benchmark conditions: all measured figures above are from the engine's own benchmark on an Intel i9-9900K desktop under macOS, radius 8, caves on.