top of page
france-bretagne-starry-sky-2026-01-05-00-45-52-utc.jpg

Spherical Voronoi with Smooth Boundaries

Writer: Luka Jankovic
Luka Jankovic
Nov 16
4 min read

Both tectonic plates and biomes require dividing a planet into regions. A Voronoi diagram provides a starting point: distribute generating points, or sites, across the sphere, then assign each surface point to its nearest site. This way calculations like biome or tectonic simulation can be done for a single voronoi site, and the results distributed across all the sufficiently close points in a consistent manner.

However, identifying the region containing a point is only part of the problem. Taking into account only the closest region would lead to discontinuities at the equidistant locations between multiple sites. The solution is to find the exact distance from the line separating the two regions to the point and use that distance to blend between the two regions. This gets exponentially more complicated when multiple sites can represent a single region (ex. a single tectonic plate consists of 20-100 voronoi sites).

Planet Architect uses a shared algorithm to estimate these boundary distances and turn them into continuous transitions.


Building regions on a sphere

The sites begin as a Fibonacci distribution across the sphere, with seeded perturbations introducing variation. Each site receives a region label, such as a tectonic plate or biome.

Multiple sites can belong to the same region. Their individual Voronoi cells therefore form a larger shape, and boundaries between cells with the same label should not create a visible transition.

To find nearby sites efficiently, I use a Cartesian KD-tree. Since the sites lie on the same sphere, ordering them by straight-line distance gives the same nearest-neighbor ordering as angular distance. This allows the spatial search to use squared Cartesian distances, reserving angular calculations for the boundary algorithm.


Finding the distance to an edge

For a terrain sample P, the nearest site A identifies its region. The algorithm then examines nearby sites belonging to other regions.

Consider one such site B. If these were the only two sites, their boundary would lie on the great circle equidistant from them. With additional sites, only part of that great circle may remain a valid boundary.

I first calculate a local distance estimate for the two-site case. The positions of A, B, and the planet center define a plane. I project P into this plane, then compare the projected direction with the spherical midpoint between A and B.

For plane normal n, midpoint M, and sphere radius R, this becomes:

This measures the angular offset in that cross-section. It is a local approximation to the shortest spherical boundary distance.


Checking whether the edge actually exists

The two-site calculation assumes that the proposed boundary is not interrupted by another cell.

To test this, I construct a boundary test position using the midpoint and the component removed during projection. Nearby sites outside B’s region are then compared against B at that position.

If another site is closer, the proposed edge location is blocked. In the diagram below, we can see a case where the site C blocks the edge between A and B, so simply returning the distance to the red line would underestimate the true distance to the boundary.

Finding spherical corners

A Voronoi corner occurs where three sites are equally distant. On a sphere, this can be calculated directly from their positions.

For three non-collinear sites A, B, and C at the same radius, the direction toward an equidistant point is perpendicular to both B − A and C − A. Their cross product therefore gives two antipodal candidates:

Out of those two, I pick the one closer to the other sites using a dot product check.

However, being equidistant from three sites does not automatically make the candidate a valid corner. Another site might be closer, in which case the corner would not actually exist. Each candidate is therefore checked against the other nearby sites, and invalid candidates are discarded.

The algorithm then goes through all the surviving corners and finds the distance to the closest corner from the sample.

So, instead of using the naive distance d to the region B, we use the distance from P to Q.

With this, we can find the correct distance to the closest boundary for any sampled point and any candidate region. Now we simply loop through all the regions (C and B in this case) which exist in the locally sampled set of voronoi sites and store the distance to the boundary of each one.


Turning distances into smooth transitions

The boundary distance can now control how strongly a neighboring region influences the terrain sample.

To blend the distance from one region to another, I use the quintic smoothstep function:

Its first and second derivatives are zero at both endpoints, allowing the blend to settle gradually into the region interiors. For a neighboring region at distance d, with transition width b, I calculate a pairwise owner weight:

At the boundary, this gives equal influence to the two regions. At the outer edge of the transition band, the neighboring influence reaches zero.

To combine several neighbors, the owner starts with a relative weight of one. Each neighbor receives a relative weight of (1 − s) / s, after which all weights are divided by their total. If several regions meet with zero estimated distance, they receive equal weights.


Below is an example of what a regular voronoi transition looks like (left) versus a smooth one with this algorithm (right).


Keeping the calculation practical

Searching every voronoi site for each terrain sample would be incredibly slow, especially due to the corner check which is O(n^3) in the number of sites. Therefore, these optimizations ensure the practicality of the algorithm:

  • Boundary-site indexing. Sites whose nearby neighbors have different region labels are retained in a smaller search index.

  • Local candidate searches. Radius queries limit the sites considered around each terrain sample.

  • Early rejection. Candidates beyond the transition width are rejected before the more expensive corner search.

  • Reusable buffers. Query results and temporary corner lists are reused throughout a chunk’s generation.

The implementation uses local candidate sets and approximate boundary distances, rather than constructing a complete spherical Voronoi mesh. These choices make it practical for repeated terrain sampling, calculating the correct transition in most non-degenerate cases.

 
 

SUBSCRIBE TO MY BLOG

bottom of page