Hexagonal Lattices for Terrain Rendering

Written between October 2026 and December 2026

Landscapes, mathematics, computer graphics and, of course, hexagons have always appealed to me. This post is about drawing a simple landscape: a bit of terrain, right here in the browser. We start from a square grid, move to a hexagonal lattice, and see how to do it along the way. There is some simple shading, but no advanced techniques.

Before we get to an actual landscape, with hills and valleys, we need a way to structure our data. We start with a regular lattice: points at even spacing, seen from above. Later, each point will carry the height of the ground at its spot. For now, it is just a square grid, and we won’t worry about resolution, that is, how many points there are and how much distance there is between them.

Connect the points with lines and we get a square lattice. Anyone who grew up with paper maps will know it. City maps and road atlases had these squares printed over them, and an index at the back told you which square to look in for your street, or, on a map of a larger area, for your town. The grid is arbitrary, but easy to understand, and we can lay it over any surface seen from above. We won’t worry about the curvature of the Earth either. At this scale, everything is flat enough.

We could already render a landscape from these squares, in principle. But once we give each point, or vertex, a height of its own, the four corners of a square no longer lie in one plane, and the square is no longer a flat face we can draw. Three points always lie in one plane, unless they sit on a line, and triangles are what graphics hardware draws anyway. So we cut every square into two triangles. Which diagonal to cut along is an arbitrary choice, so we pick one and cut every square the same way.

Now every point needs a height. We could draw a height map by hand, or take measured heights from a real place on Earth, or from anywhere else that has been mapped. We could run a terrain generator that simulates erosion and similar processes. Here we use random noise: several layers of simplex noise stacked on top of each other. It looks enough like terrain and takes almost no effort. Lifting every point to its height turns the grid into a mesh, drawn here as a wireframe.

To make it look more like a landscape, we fill in the triangles and colour each one by its height. Low triangles are green. Higher up, the colour turns a yellowish brown, then grey, and at the top of what are now mountains, white.

Each triangle has one colour, from its average height, so neighbours differ slightly and every triangle stands out. We could make the triangles smaller, and keep going until the largest one covers a single pixel of the image. Then the colour would look smooth, but it would take a great many triangles and a lot of work for the renderer. The guiding idea of triangle-based graphics is to use as many triangles as necessary and as few as possible. So we keep the triangles and get more careful about how we colour the pixels inside them.

We give each vertex a colour instead of each triangle. Every pixel then mixes the colours of its triangle’s three corners, weighted by where on the triangle it sits. The weights are called barycentric coordinates:

c(P)=λAcA+λBcB+λCcCλA+λB+λC=1\begin{gathered}c(P) = \lambda_A c_A + \lambda_B c_B + \lambda_C c_C \\ \lambda_A + \lambda_B + \lambda_C = 1\end{gathered}

Here PP is the pixel, AA, BB and CC are the three corners of its triangle, and cAc_A, cBc_B and cCc_C are the colours at those corners. The weights λA\lambda_A, λB\lambda_B and λC\lambda_C are the barycentric coordinates of PP: how much each corner counts. Each one is the area of the small triangle that PP forms with the other two corners, divided by the area of the whole triangle. A pixel right on corner AA gets λA=1\lambda_A = 1 and takes the colour of AA; a pixel in the middle gets a third of each.

That is barycentric interpolation, and the GPU does all of it for us. For every pixel it works out the barycentric coordinates and interpolates any value we attach to the vertices, in dedicated hardware, fast enough for millions of pixels in every frame. The colour now runs smoothly across the edges.

The terrain still looks flat. To bring out its shape, we light each face by how it is turned towards an imaginary sun. First we fix the direction the light comes from, ll, a unit vector pointing towards the sun. Then we work out which way each face points: its surface normal, from the cross product of two of the triangle’s edges:

nf=(b−a)×(c−a)∥(b−a)×(c−a)∥n_f = \frac{(b-a)\times(c-a)}{\lVert (b-a)\times(c-a) \rVert}

The scene draws the normal of one triangle per grid cell as a short arrow from its centre, so the arrows stay readable, and the long arrow is the light direction.

How much light a face gets is its brightness bfb_f, the dot product of the face’s normal with the light direction:

bf=max⁡(0,  nf⋅l)b_f = \max(0,\; n_f \cdot l)

It is 1 for a face turned straight at the sun and 0 for a face parallel to the light or turned away from it. Past that the dot product goes negative, and we clamp it to 0. We multiply the face’s colour by that number and by the colour of the light, here a slightly warm white.

Now the individual faces show again: the brightness jumps wherever two triangles meet.

So we do what we did with the colours and interpolate. For that we need normals at the vertices, and we get them by averaging: for each vertex we add up the normals of all the triangles around it, as their raw cross products, and normalise the sum.

nv=normalize⁡(∑f∋v(bf−af)×(cf−af))n_v = \operatorname{normalize}\Big( \sum_{f \ni v} (b_f - a_f)\times(c_f - a_f) \Big)

Then, for every pixel, we mix the normals of its triangle’s three vertices with the same barycentric weights we used for the colour, and light the pixel with the result:

n(P)=normalize⁡(λAnA+λBnB+λCnC)n(P) = \operatorname{normalize}(\lambda_A n_A + \lambda_B n_B + \lambda_C n_C)

So, yes, we start with face normals, average them around each vertex to obtain vertex normals, and then we use those vertex normals to compute pixel normals on the original faces!

That sum has a useful property. A cross product is as long as twice the area of its triangle, so larger triangles count for more, and we never need to explicitly compute a single area. For a height field like ours, there are even cheaper ways to estimate normals from the heights alone, such as central differences, but we won’t need them here.

What we have built is called Phong shading. The mesh has not changed at all, only the way we shade it, and it arguably looks much smoother.

Let’s go back and reconsider the flat grid we started with. The squares feel kind of arbitrary. We used them because right angles and Cartesian coordinates are the default. But really, natural landscapes don’t tend to come in right angles. Even more arbitrary is the direction in which we cut them into triangles: every diagonal leans the same way, and we may just as well have chosen the other direction.

These parallel diagonals can show up as rendering artifacts in certain cases. We can alleviate that somewhat by flipping the diagonal in every other row. The cuts then zigzag, one row leaning right and the next leaning left, so both diagonal directions occur equally often. That doesn’t truly remedy the arbitrariness, though, and the triangles are still right-angled, but it is a step in the right direction.

From here, rearranging the points slightly takes us to equilateral triangles, and you may spot a hexagonal lattice appearing. We shift every odd row by half a spacing and move the rows a little closer together, to 3/2\sqrt3/2 (about 0.87) of the point spacing. To keep the number of points per area fixed, we scale the spacing up a bit:

xij=(i+12[ j odd ]) azij=32 j aa=s2/3\begin{gathered}x_{ij} = \big(i + \tfrac12 [\,j \text{ odd}\,]\big)\,a \\ z_{ij} = \tfrac{\sqrt3}{2}\, j\, a \\ a = s\sqrt{2/\sqrt3}\end{gathered}

Here ii and jj count the columns and rows, xijx_{ij} and zijz_{ij} are where point (i,j)(i, j) lies on the ground, and aa is the new spacing between neighbouring points. The bracket [ j odd ][\,j \text{ odd}\,] is 1 in odd rows and 0 in even rows, which is the half-spacing shift. The old square spacing is ss. A square cell of area s2s^2 holds one point, a cell of the new lattice, of area 32 a2\tfrac{\sqrt3}{2}\,a^2, holds one point too, and setting the two equal gives aa.

And just like that, every formerly right triangle has become equilateral. The points are still the same points, there are just as many of them as before, and they sit in the same rows and columns of the same array. Only where each one lies on the ground has changed slightly, and, thereby, the angles between lines.

Smaller hexagons appear when we draw Voronoi cells around all vertices. It looks like the typical hex grid you may know from board games and video games such as Catan and Civilization V. Its centres are exactly the vertices of our lattice, and its edges cross the triangle edges at right angles. In this representation, each field has six neighbours, all at the same distance aa and 60° apart. This is in stark contrast to a square grid, where players argue about whether a given field has four or eight neighbours. It shares edges with four other fields, but in the diagonal directions, there lie four more fields, touching the centre one only at a single point each. Worse, the distances between the two types of neighbours are ss and s2s\sqrt2.

Before we look at the advantages of hexagonal lattices, we must point out one major disadvantage. On computers, images are stored as arrays of square pixels, and height maps are images. A hexagonal lattice still fits into an array: rows of points, every other row shifted by half a spacing. But no established software knows or cares about the shift. Image editors, GIS elevation data and terrain tools read arrays as square grids, and draw simple square lattices. Real height data comes as squares, and we have to resample it if we want to use it on a hexagonal lattice.

The advantages show once we do more than render. Often we also want to simulate something on the terrain, and most simulations work on neighbourhoods.

So let’s do something organic and grow ourselves a digital forest on our lattice. We simulate it such that a stand starts from a single tree, and, at each step, it seeds another tree in an empty neighbouring field, with probability 0.85 (which is arbitrary but high). Ideally, we’d see a forest that resembles a circular disk forming around the original tree. Whether you allow four or eight neighbours, on a square lattice, you will always end up with a rectangle. The hexagonal lattice, on the other hand, yields a hexagon, which is a much better approximation of a circle.

If we lower the seeding probability, all three versions round off, because chance then outweighs the lattice. In general, the faster a process spreads, the more of the lattice’s shape it shows. More general flows, such as water running downhill, are computed over neighbourhoods in the same way. The resulting flow fields can be used for all kinds of efficient simulations, such as unit movement in real-time strategy games like Planetary Annihilation.

Move your cursor over the terrain and the cells under it are highlighted: one cell, its six neighbours and the ring around them, 19 cells in all. Click or drag to plant trees on those cells. Switch to a square lattice and try the same with a rectangular brush. This is where squares feel absolutely wrong (or tell me if it doesn’t).

There are other ways of manipulating terrain, but this is one where the manipulation and the cells for the simulation are shared, which is very precise and easy to follow: what you click on is exactly what the simulation works with. I turned this into a little game about reforestation: Sylvatica.

We have built a terrain renderer on a common square grid, and turned that into a hexagonal lattice. It is super basic, but it is still the technology that most modern graphics engines are built on. Yes, even GTA 6 (although that one uses a host of further, very exciting, methods).

There is a lot more we could explore. Our terrain is shaded but it casts no real shadows. Every triangle is drawn at the same size, near or far, where adaptive tessellation could improve fidelity and performance. And, because 2-dimensional heightfields have only one height per point, we cannot render overhangs or caves. Maybe I’ll explore some of those things in the future, in a similar manner.

Jan Philip Göpfert's profile picture

About the Author

Jan Philip Göpfert is a researcher and strategist who examines the gap between how business frameworks are supposed to work and how they actually perform. Based in Germany, he combines technical background in AI systems with practical experience in startup operations and strategic consulting. His writing challenges conventional wisdom when the evidence demands it, providing the deeper analysis that consequential decisions require.