Contact

Type to explore Drawk studio productions

Discover cross-platform games, mobile apps, architecture articles, and interactive GLSL labs.

← Back to Posts

A Custom Voxel Engine: C++ Core, C ABI, Unity Layer, and Six Worlds From JSON

Updated November 24, 2026 · Previous versions & history ↓

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.

Dusk Synth World 1 of 6: dusk-synth
A voxel city avenue at sunset with a striped sun at the end of the street, neon windows in pink, cyan and amber, and glowing road lines
Dusk Synth: the first world, a vaporwave avenue with the sun always at the end of the street. Everything in this frame comes from one style file and the same engine core as the other five worlds.

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:

  1. 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.
  2. 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.
  3. 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

flowchart TD subgraph DATA["JSON Contract (voxel-style, -blocks, -terrain, -volume, -pois, -items)"] J1["Styles, blocks, terrain, prefabs, POIs, items"] end subgraph CORE["C++17 Core (no dependencies)"] C1["Chunks, palette storage, greedy meshing, light, terrain, streaming, regions"] end subgraph ABI["C ABI (voxel_c.h, C99)"] A1["Flat functions: any language can call it"] end subgraph CS["C# Binding + Pure C# Runtimes"] S1["P/Invoke wrappers, POI runtime, items runtime (engine-free)"] end subgraph UNITY["Unity Layer"] U1["Streaming world, chunk renderer, shaders, style looks, weather, demo host"] end J1 --> C1 C1 --> A1 A1 --> S1 S1 --> U1
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

Dusk Synth World 2 of 6: rural-canyons
Voxel desert canyon with red, orange and cream rock strata, a river at the bottom, and trees and rock formations on the mesa
Rural Canyons: late afternoon on a mesa edge, looking down a canyon wall banded in warped strata with a river below.

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

Dusk Synth World 3 of 6: sky-islands
Grassy voxel peak above a sea of cloud with marble ruins, trees, and floating islands in a pink sky
Sky Islands: a grassy peak breaking through the cloud sea at a pink late afternoon, with floating islands hanging beyond it.

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

Dusk Synth World 4 of 6: sunken-coast
Half-drowned weathered voxel towers standing in shallow turquoise water at a peach and coral sunset
Sunken Coast: weathered towers rising out of a glassy turquoise sea under a low coral sunset.

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

Dusk Synth World 5 of 6: frozen-arcology
A stepped voxel arcology with lit windows over a snowfield at night under a green aurora sky
Frozen Arcology: the lit arcology across open snow at night, under an aurora sky with snow falling.

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

Dusk Synth World 6 of 6: jungle-ruins
A mossy stepped voxel temple covered in vines, surrounded by jungle trees and ferns in green haze
Jungle Ruins: a mossy step pyramid swallowed by vines, seen through the green height fog of the valley.

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.
Dusk Synth gameplay POI: Radio DJ
A voxel avatar in a neon alley in front of a glowing DJ booth with an E Talk prompt and a hotbar showing the Zapper
Radio DJ: a talk interaction at a glowing booth. The prompt, label and hotbar are all driven by the POI and item data.

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.

Dusk Synth gameplay POI: Signal Tower
A voxel archway with a green and cyan beam, a hold E to Activate prompt with a progress bar, and a Build Pad nearby
Signal Tower: mid-hold on the activate interaction. The bar is the hold progress; releasing or taking a hit resets it.

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.

Dusk Synth gameplay POI: Bass Cannon
A freshly built Bass Cannon, a striped column with a magenta head and a glowing yellow top, standing on a glowing cyan build pad in a neon street, with its ready label above it
Bass Cannon: built from a pad for 10 Light and ready to fire down the avenue.

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 .vox Format: 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.v1 follows.
  • 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.

← Back to All Posts