hourigan.info - portfolio ·

work

live

~/

portfolio

›

src

›

work.done

›

<

section

hero

/>

⌘K palette

⌘P files

main

↓0↑2

0 errors

open_to_work

UTF-8

•

HTML

•

Cincinnati

02:40 PM

voxelMeta

Voxel Terrain Editing

sdfs

marching squares

author time

cooking

Uncommon Games

Animalkind

2026

The Problem: terrain modding was only achievable with player terrain

Animalkind uses a voxelized terrain system that operates via signed distance fields and a marching-square algorithm, and initially terrain was authored by baking height maps into voxel data to create the base terrain shape. Because height maps are two-dimensional and only capable of encoding a height change from a single top-down perspective, naturalistic terrain with realistic angle changes and indents like caves and overhangs are structurally impossible. To overcome this, caves and other details were added via terrain-editing tools that were initially created so players could edit the terrain themselves. This allowed caves and other geometry to be added into the larger bulk structure, but came with significant limitations and a very high degree of friction. Adding details to worlds was time consuming, inelegant, and was strictly limited by mechanics we'd tied to player objects, and thus lacked a traditional edit-feel.


modifying terrain with the player tools limited us to player movements, meaning most feature changes were flat, uninspired, and took forever to author

The Solution: turning player tools into editor tools

In order to increase the speed, accuracy, and flexibility of our editing tools, it became clear that breaking outside of this player-flow was necessary. Rather than build or rely upon a parallel editor that lives outside of Unity or this framework, I instead decided that the most-reliable way to know what our terrain would look like at runtime was to actually author it within the same functional system as our game. To that effect, I pulled our current player tooling out of the player space and into the editor space with two #if UNITY_EDITOR entry points to our existing ChunksManager and routed editor brush operations through the exact same modifyVoxelField path that the player tools utilized. Thus, the editor isn't a special case here, but rather the same machinery entering through a different door. Every fix, adjustment, and feature expansion made to the core pipeline propagates both to the player tools and the editor system simultaneously, keeping them in line and centralized.

How do you turn player tools into editor tools? Very very carefully.

The Result: infinitely tunable editor tools with custom SDF brushes

The result is a full brush-based sculpting system supporting our core features, and some new ones: dig, add, smooth, level, paint, roughen, an SDF stamp brush that accepts arbitrary signed distance field shapes with configurable orientation, scale, and strength, and a history brush that serves as a reliable "undo" feature. The SDF tool in particular required resolving a sequential chain issues, the most significant being the gradient artifacts that also impacted the other tools, with each fix exposing another issue. This deeply overhauled our previous terrain editing pipeline, made terrain adjustments more accessible to the wider development team, unlocked a workflow that was more legible to world designers, and collapsed innumerable processes that often took hours to produce worse results into a singular action that took mere minutes and was infinitely more flexible, saving hours of effort just within its first week of implementation by allowing us to do things like instantly delete unsightly terrain from our trailer and make our caves look more naturalistic.

Key Features
  • Editor-level terrain edit brushes

  • Intuitive brush mechanics

  • Custom SDF Brush authoring

  • History-brush erasing

  • Terrain material painting

  • Y-slicing and Y-masking

Results

0

dev time

0

dev time

0

decrease in authoring time

0

decrease in authoring time

0%

increase in tool versatility

0%

increase in tool versatility

0%

Sanity saved in further projects

0%

Sanity saved in further projects

The full

/////////////////////////

The full

/////////////////////////

/////////////////////////

STORY

/////////////////////////

STORY

The full

/////////////////////////

/////////////////////////

STORY

details for nerds

What we had vs what we wanted

Animalkind's voxel terrain system works essentially identically to all voxel terrain systems that aren't Minecraft's: a voxel field utilizes something called Signed Distance Fields, where each voxel holds a value that says "how far away from the surface am I?" Instead of being a data point holding a terrain value itself, it is more of a gradient field; it's inherently fuzzy. Along with this value, voxels are "signed," where positive values are "above ground" and negative are "below ground," meaning the terrain surface itself is generated where this boundary crosses from positive to negative, what's called the zero-crossing boundary. Terrain, therefore, doesn't exist as a traditional mesh, but rather is emergent from the calculations within this field, and understanding this on a fundamental level helps make it clear why the editing tools we use operate the way they do, and what their limitations actually are.

SDF Field
This probably doesn't help you but I wanted to make it anyway.
Speed
Radius

Before this tool existed, we authored heightmaps using a combination of mixed program applications, specifically Photoshop and Unity's Terrain Toolkit. A heightmap is a texture file that stores a single height value per pixel, with black being 0, the lowest point, and white being 1, the highest. This can create a number of potential issues depending on bit depth and other formatting factors, the worst of which being visible stairstepping artifacts.

This issue is something that can be worked around, but this is a lot like trying to calculate a useful normal map out of pure bump data; it's generally easier to accept that these mechanics operate with fundamental assumptions, and working within the right space for the right problem is the real solution.

The other limitation, as mentioned before, is the complete inability to encode and translate features like overhangs and caves into this system. To work around this, we would generate our base heightmap-level terrain at our initial runtime, and then use player-facing terrain editing tools to add features to the terrain we imagined would be interesting or useful to the players' play experience. While passable, this came with all the limits one might expect from using tools designed for player use to fill a design role: they were slow, clunky, inflexible, and directly hampered by the mobility of our player character units.

This was our original terrain-authoring flow. The Terrain Toolkit remains attractive as an initial authoring tool since it operates much more quickly than voxel evaluations.

Therefore, the goal at the outset was to unshackle our editing pipeline from the player hook and, ideally, from the heightmap one as well and instead engage directly in the same three-dimensional space our voxel field exists within. This simultaneously expands the creative flexibility of terrain creation, the speed in which it's enacted, and the immediate feedback of seeing our actual terrain system generated from the edits, thus removing ambiguity from the authoring process. The fastest and smoothest path forward, therefore, was to uplift the player tools into the editor space, thus sidestepping the challenges that lay latent in introducing a new tool entirely-- everyone on the team is already familiar with Unity, after all.

The code's already there, let's use it

Since much of the code for editing voxels within our system already existed on a player-level, it made the most sense to snatch that code up and hook into it, which was incidentally rather trivial. Since the editor goes through the exact same modifyVoxelField -> ApplyVoxelPaternAtAbsoluteWorldPoint path as player tools, every adjustment to the system propagates to both toolsets. There is presently a practical constraint here, though: ChunksManager and its singleton infrastructure are runtime components, meaning the editor still requires play mode to function. This is unideal because there is quite a lot of unnecessary overhead in the play environment, but this can be mitigated by removing unnecessary components while engaging the tools. A perfect solution would involve a lighter-weight implementation, but the time constraints for this tool (less than a week of development time, most of the functions were plugged in over the course of a few days) meant that certain concessions had to be made.

//Plugging into code and a system that was already there saved a lot of time in constructing this tool, since a bespoke pipeline could be sidestepped. The alternative was constructing an entirely new architecture--no thanks. The tradeoff is that it still requires play mode to operate.

Making it for humans

Voxel fields using SDFs are very efficient at storing and computing terrain data, but they break with several intuitions people have about how things ought to work, especially if they have experience with 3D topology, modeling, or even photoshop. A voxel field does not behave like polygon sculpting or even heightmap editing. Since the surface is computed from the field indirectly, this violates several assumptions artists, designers, and even engineers might make about its functionality.

Therefore, one of the primary goals of this implementation wasn't to just bring the editing tools out of the player space and into the editor space, but also to change their behavior and construct the UI/UX interface so that it more accurately aligned with artist and designer expectations, which is decidedly nontrivial to solve.

Making the brush feel like a brush

Our initial player tools were built with single-actions in mind, meaning a single stamp per click, meanwhile a digital brush stamps multiple times per button-hold and operates additively over time. Thus, after constructing the initial UI/UX interface, it became clear that adding this sort of behavior into the system was the most important initial change. Thankfully, the core construction of the tool wasn't mutually exclusive with this idea, it just operated differently as a player object, and I just had to add a brush rate function that drove the fire-rate of the brush tools:

double interval = (1.0 - _brushRate) * (1.0 - _brushRate) * 2.0

At _brushRate = 1.0 the interval is zero and the tool fires every update. At lower rates, the squared curve front-loads the slowdown, thus a rate of 0.5 gives an interval of 0.5s rather than 1.0s, which keeps the brush feeling responsive even at low settings, and sits core to the thesis of this tool's intended purpose: to be responsive, snappy, and intuitive. A tool that updates over time instead of clickable bursts was a wholly new concept to the team, and it's deeply powerful by comparison.

SDF brushes and gradient distortions: a match made in heck

The use of custom SDFs for brushes already existed, though unutilized, in our original player editing toolkit, so integrating and expanding the functionality of this feature felt like a requisite for getting this tooling to realize its full potential. As one of the major authoring issues we have had is making our terrain feel organic, the best way to make terrain naturalistic is to allow for an element of chaos and happy accidents, things that pure roughness functions and spheres can't really introduce. This meant that I had to both expand the size limits of our previous brush technology and deal with several poor assumptions our mathematics were making.

Fixing the SDF math meant we could make mountain-sized terrain from any shape

…
…

You can spin these, by the way, it's very fun, I highly recommend it.

Gradient distortions: the BothAir problem

Gradient distortions were a disease that infected both our normal brush tooling and the SDFs; it was largely invisible in the normal use cases of our tools because they were originally not very supportive of expanding through too many chunks at once and also had baked-in size limits. At small radii, this issue is essentially invisible, but as I increased the effective radius of the toolkit, it became clear something was off about our math, as there were very noticeable ridges and stairstep-like distortions being encoded into the stamping. The core problem was housed in the modification logic in how it determined brush boundaries:

mode == TerrainModificationMode.Add && oldValue > surfaceValue
    && (newValue <= surfaceValue || bothAir(oldValue, newValue, surfaceValue))

bothAir fired when both oldValue and newValue were positive, and the additive formula still applied: oldValue + newValue * strength. Both positive means the result is more positive, ergo the voxel moves deeper into air. Across a large brush region this pushed thousands of air voxels outward, distorting the gradient field surrounding the stamp. The mesh extractor then found zero-crossings in places the stamp never touched, producing ridges, halo geometry, and stairstepping outside the intended shape.

the bothAir check created these really unsightly ridges during terrain editing

…
…

they could be smoothed away but that created more work than was necessary in authoring

To fix this, I had to change our assumptions to operate within the logical space of the voxel field itself and remove the bothAir check and make it so value changes only fire when the brush explicitly outputs a solid (or negative in the case of dig) value. This way, only voxels in the correct phase for the operation are touched. This then allowed me to expand the brush's radius to technically infinite size without introducing distortions. As a happy accident, this also reduced the number of voxels being operated on and evaluated per use, thus speeding up the tool's responsiveness. I still capped the tool at a 40 voxel radius unit; this sounds small, until you realize that in order to run our operations correctly, we have to multiply the brush size by 2 for the smooth tool in order to sample voxel values correctly.

removing bothAir and enforcing value changes so that only voxels in the correct phase are touched



…
…

this has tradeoffs but ultimately they're better than the alternative, and further changes could mitigate the drawbacks

An increase from 40 to 50 sounds small on paper, but in the standard brush that's 255,000 more voxel values that need evaluated, just shy of a 200% increase in compute, and for smooth it's even more dour, adding over 2 million voxels into the raw pool. This can be circumvented with smarter evaluation techniques and perhaps even compute shaders since the math is actually quite simple and derives largely from lookup tables, but that requires a significant refactor of our base system and was far outside the scope of this tool's intended solution.

Core: 268,083 voxelsSmooth shell: ≈1,876,578 voxelsTotal impacted: 2,144,661

This adjustment made both the base tools and the SDF custom brush tool operate more effectively, allowing correctly-authored SDFs to be represented more effectively and to serve a multifunctional role as both bulk and detail tooling, changing the entire landscape of our previous solutions.

History is doomed to repeat itself: a quick overview of other tooling

The history brush

Our world blobs can be saved into a compressed binary format, which is our primary tool for loading and distributing world information internally. These serve as snapshots of our game world, and so I created the history brush to take advantage of this function by loading it as a reference field, allowing the user to back up changes with a single button press and also revert mistakes quite easily.

The Y-slicer

The most advantageous reason to use an editor tool rather than a player tool is the a capacity to sidestep limitations that would otherwise hound the player, such as requiring target terrain in order to make edits. The Y-slicer creates a cross-sectional slice of the visible terrain and fabricates a plane-target for the voxel brush to cast onto, allowing interior tunnels to be authored without Mother Terrain actually existing. 

Terrain paint tool

Animalkind's terrain values are also stored in the voxel field and operate via a voting system, so it was vital to make sure that this function was extant in this tool as well. Incidentally, it works remarkably well at cleaning up some of the digital-feeling artifacts that are baked into our current terrain evaluations, indicating that our system is capable of delivering far more detailed terrain than initially expected.

Hover preview

This also already existed in our toolkit for players, though it's rarely utilized. It is quite expensive, as it essentially runs the full voxel evaluation and marching cubes without committing the changes, so for large operations it can be VERY slow. Regardless, it is necessary for some edits since it allows more predictable results.

1
1