How to Build a Low Poly Terrain Mesh with Dynamic Resolution, Part 2: Chunking
Terrain chunking turns one heightmap into several smaller meshes that fit together. Each chunk starts with two triangles. A density map tells the generator where to split them, and a seam pass keeps neighboring chunks from leaving cracks.

Each chunk has its own renderer and bounds. Unity can cull chunks outside the camera view, and an edit can rebuild only the chunks it affects. Smaller chunks give you finer control over both, at the cost of more renderers to manage.
Step 1: Give each chunk its own two starting triangles
A height sample is one point. A cell sits between four sample points. Two neighboring chunks cover different cells, but both read the sample column where they meet.

The Unity demo uses 32 cells per chunk. The first chunk starts at X = 0 and ends at X = 32. Its neighbor starts at X = 32 and ends at X = 64. Calculate each chunk's corners in the full heightmap so both sides refer to that shared column with the same coordinates.
int x = chunkIndex % grid * cells;
int z = chunkIndex / grid * cells;
var a = new Vector2Int(x, z);
var b = new Vector2Int(x, z + cells);
var c = new Vector2Int(x + cells, z);
var d = new Vector2Int(x + cells, z + cells);
Refine(new Triangle(b, d, a, 0), leaves[chunkIndex]);
Refine(new Triangle(c, a, d, 0), leaves[chunkIndex]);The triangles share the diagonal from A to D. Each split cuts the longest edge in half. The children keep a fixed vertex order so their longest edge is always between their second and third corners.
Vector2Int midpoint = (parent.B + parent.C) / 2;
left = new Triangle(midpoint, parent.C, parent.A, parent.Depth + 1);
right = new Triangle(midpoint, parent.A, parent.B, parent.Depth + 1);Part 1 compared each triangle to the heightmap. Here we first build a density map. At each sample, count how many of its eight neighbors differ in height by at least a threshold. A flat area requests few extra splits. A steep slope can request several. For each triangle, read the map at its three corners and center, then use the highest value to decide the target depth. A triangle that stops splitting is a leaf. Save each chunk's leaves and mark their vertices on the shared grid.
Step 2: Stitch the leaves across chunk borders
Say the left chunk splits a border triangle and adds a midpoint. The right chunk may still have a single edge spanning that point. This produces a T-junction between the two meshes.
Choose the leaves for every chunk before emitting faces. Then revisit each leaf and check whether the midpoint of any edge is marked. If one is, split the leaf using the same longest edge rule as before. If the marked midpoint is on a shorter edge, the first split makes that edge the longest edge of a child. A later split can then reach the required midpoint without changing the tree's split order.
Mark the new vertices and repeat the seam pass until no leaf needs another split. A forced split can add a point that a triangle visited earlier also needs. Both sides then use the same edge segments and read the same heights.

The standalone Unity demo resamples the 513 by 513 Mountain00 heightmap from the Polaris samples to 97 by 97. It checked face winding, verified that every interior edge joins two faces, and matched 137 edge segments across all 12 internal chunk borders. A height difference threshold of 0.32 Unity units produced 2,877 triangles. Uniform subdivision to the same depth cap of 8 would produce 4,608 triangles across the nine chunks.
A mesh can still show a lighting seam when the positions match. For smooth shading, use the same border normal on both sides, for example by looking up heights on both sides of the border. With the flat shaded demo, each face keeps its own normal.
Step 3: Fill the vertex buffers with Unity Jobs
After stitching, each chunk has a list of corners in groups of three, one group per triangle. Each corner is still an integer coordinate in the heightmap. This job turns one corner into one Unity vertex. The flat shaded mesh gives each face its own vertex records, even where positions match.
struct BuildTriangle : IJobParallelFor
{
[ReadOnly] public NativeArray<float> Heights;
[ReadOnly] public NativeArray<Vector2Int> Corners;
[WriteOnly] public NativeArray<Vector3> Positions;
public void Execute(int index)
{
Vector2Int point = Corners[index];
Positions[index] = new Vector3(point.x * Spacing,
Heights[point.y * Side + point.x], point.y * Spacing);
}
}Side is 97, the number of samples in one heightmap row. Spacing is 0.75 Unity units between samples. Each job reads the same height buffer and writes to a separate positions buffer. Each iteration owns one output index, so workers can run in parallel.
for (int chunk = 0; chunk < triangles.Length; chunk++)
{
inputs[chunk] = new NativeArray<Vector2Int>(
triangles[chunk].ToArray(), Allocator.TempJob);
outputs[chunk] = new NativeArray<Vector3>(
inputs[chunk].Length, Allocator.TempJob);
handles[chunk] = new BuildTriangle
{
Heights = heights, Corners = inputs[chunk], Positions = outputs[chunk]
}.Schedule(inputs[chunk].Length, 32);
}
JobHandle.CompleteAll(handles);The demo chooses and stitches triangles before scheduling these jobs. After the jobs finish, it creates the meshes and recalculates normals on the main thread. Dispose the native buffers after reading them. Count vertices after stitching and choose an index format that fits. Unity supports 32 bit indices on compatible targets.
Terrain chunking in Polaris
We implemented mesh chunking in Polaris, a mesh terrain editor for Unity. Its Grid Size setting splits terrain geometry into chunks, and the neighbor settings match geometry across connected terrains. Polaris uses Unity's C# Job System for geometry generation work on worker threads where multithreading is available.

FAQ
Do adjacent chunks need to share a vertex buffer? No. Each chunk can store its own copy of the border vertices. Both meshes must trace the same border segments.
Does chunking reduce the triangle count? Chunking alone does not reduce the triangle count. Adaptive subdivision reduces the geometry here, and chunking lets the renderer skip out of view chunks.
Can I rebuild just one chunk after painting a height? Yes, if the edit only affects samples used by that chunk. Include neighbors if the edit changes a shared sample, the border splits, or the normals computed from those samples.
Try it
Start with a 3 by 3 chunk grid, or get Polaris Summit on the Unity Asset Store.



Comments