Rill & Reef: How I Turn the Real Earth into Hex Tiles

Rill & Reef is a cozy fishing game I am working on. Its world is the real Earth, redrawn as hex tiles you can travel across, with seasons and weather on top. There is nothing to play yet, and this note is not about fishing. It is about the map: where the geography comes from, how a coastline or a mountain range becomes a set of tiles, and the places where my first idea was wrong.

Rill & Reef hex world map in summer: green hex tiles, pine trees, a lake and a sandy coastline with small islands
Summer on the Swedish coast near Stockholm: forest, a long inland lake, sandy shores and small offshore islands. Every cell here is about 25 km across.

Two rules shaped everything below. Real data decides where land, water, rivers and mountains are, and the tiles only approximate it. And the whole map is built offline by deterministic tools, so the same inputs give the same files, byte for byte. The game never generates terrain; it only draws what the tools produced.

Starting with the whole planet

My design document imagined something smaller: a world atlas of a few hundred cells, plus regional maps of 200 to 300 cells around each fishing area. When I started building, I drew the entire Earth first, at one scale, as one continuous map. Everything else has to sit on it, and I wanted to know early whether real places stay recognisable once they are reduced to hexagons.

The art is KayKit’s Medieval Hexagon Pack by Kay Lousberg: grass, coast, river, slope and cliff tiles, plus trees, rocks, hills and mountains. Its castles, villages and roads stay out of the game. The tile rules come from Felix Turner’s open-source hex-map-wfc, which builds small island worlds from the same pack with a technique called Wave Function Collapse. I expected that technique to do most of the work. In the end it does one specific job, and the rest is plain geometry and a lot of checking.

Diagram of the eight-stage map build, from pinned open data sources through the hex grid, coasts, rivers, height and climate, relief solving, lakes and Antarctica, to the web export.
The eight stages of the map build. Each stage writes a new run named after a hash of its inputs, so any run can be compared with the one before it.

A grid that closes around the planet

The map uses Web Mercator, the projection behind most online maps: a square world that wraps left to right and stops at 85.05 degrees north and south. I tried a version where you could sail over the poles and dropped it. Wrapping only sideways keeps the camera, the tile rotations and every neighbour lookup simple.

On that square sits a grid of flat-topped hexagons. I wanted cells about 25 km across, but the grid also has to close exactly at the date line, so that sailing east from Fiji reaches Samoa without a seam. With hex coordinates that only works if the number of columns around the world is even. The nearest even count is 1,850, which makes each cell 25.013 km across and gives 2,964,625 cells, and the seam closes to within a few billionths of a metre.

Mercator has a cost I accepted knowingly. At 60 degrees latitude a cell covers only about half its nominal width on the ground, and near the poles far less. Antarctica alone takes about 545,000 cells, close to half of all land cells. The tiles do not care, but anything that measures area must, so the statistics below are weighted by true area on the sphere.

To decide what is land, I rasterise the Natural Earth 1:10 million land and minor-islands layers at about 3 km per pixel and read 48 sample points inside each hexagon, an 8×8 grid clipped to its shape. No land samples means water, only land samples means land, anything else is mixed: 1,789,000 water cells, 1,113,283 land cells and 62,342 mixed ones. A whole-world comparison with the source raster finds no pixel wrong by more than one sample width.

Coastlines through shared corners

A mixed cell still needs a tile. KayKit has five coast tiles, A to E, plus plain grass, each rotatable in 60-degree steps. Water cells get no tile; one shared water surface runs under the whole map. The obvious approach is to fit each cell on its own against every tile shape. The catch is that two neighbours fitted separately can disagree about the edge they share.

The version that works decides corners instead of cells. Every corner is shared by three hexagons, and the four samples nearest it in each of them vote land or water. Then each cell walks round its six corners and counts how often the answer changes. No change means grass or water. Two changes mean a run of one to five land corners, and those five cases are exactly KayKit’s five coast tiles; the rotation follows from where the run starts. Because neighbours read the same corners, their edges cannot disagree. There are no seams to fix, because none can exist.

Diagram of 37 real hex cells on the Great Australian Bight showing land and water sample points, the Natural Earth coastline, corner votes and the KayKit coast tile letters, next to the same coast in the web viewer.
Real data from the Great Australian Bight. One cell marked D has no land samples at all; it gets a land corner from its neighbours, which keeps the coastline continuous.

Two cases need care. A thin spit with water on both sides gives four or six changes, and no tile exists for that, so the tool flips the fewest corners that make the area representable, preferring flips closest to the source data. And a small island inside one cell can leave all six corners as water. Left alone it would vanish, so the corner nearest the island is flipped to land.

The trouble came in narrow places. At Gibraltar the two coasts met and the strait closed; around Greece, islands merged. At 25 km per cell, a strait a few kilometres wide is either a whole cell wide or gone. So a passage now counts only if the real gap between the coast meshes, measured at the water’s height, is wide enough to sail through, and wherever the original shoreline shows at least a kilometre of open water across a cell edge, that edge must stay open. That is how Messina and the Bosporus survive.

A survey of all 8,890,175 cell edges then listed candidate places where islands had joined or bays had closed, and I fixed only the cases I confirmed by eye. A small search solver re-tiles a named strait or island group under the same edge rules and solved 24 of 28 groups. Other confirmed problems, such as Prince Edward Island joined to the mainland, the Outer Hebrides, Ise Bay and the inner Oslofjord, were repaired cell by cell, 88 cells in all. Where stock tiles could not express the shape, as along Euboea, I built new tile geometry derived from the KayKit coast tiles. Then the opposite problem: the reopened Bosporus and four other straits were far wider than the real ones, so I narrowed them with a smooth local warp that keeps the outer edges of the repaired area fixed.

Hex-tile map of the Aegean Sea with the long island of Euboea and its narrow channel on the left, scattered Cyclades islands in the middle and the Turkish coast on the right.
The Aegean. Euboea, the long island on the left, needed 13 hand-built cells for its narrow channel, and the Cyclades stay separate islands instead of one landmass.

One change is deliberately not geographic. Homigot, the cape at the eastern tip of Korea, had become an ordinary stretch of coast at this scale. I exaggerated its tail across two cells so it reads as a cape, and the tools record it as a deliberate exaggeration rather than a repair.

Rivers that only join where they really meet

Rivers come from Natural Earth’s river and lake centre lines: 2,269 lines, traced into chains of river cells, each with a tile whose openings match where the river enters and leaves. KayKit has twelve river shapes, so the tools reshape them offline into variants for each width, junction and mouth; the map uses 543. Width comes from a second Natural Earth layer that tapers each river, sorted into small, medium and large, with mouths one step wider. These are drawing widths, not measurements, but they make the Nile clearly wider than the Suez Canal beside it.

The rule that mattered most was about junctions. On a coarse grid, separate rivers often pass through the same cell, and early runs merged them there: 506 cells joined rivers that do not meet. Now two rivers share a cell only where the source lines really cross or end, or touch the same confirmed body of water, and detours of up to four cells keep the rest apart. Where a river line crossed water that was already open sea, it had been carving channels through the coast and small islands; those 130 cells now keep their original coast. All 514 river mouths connect to the end of their own river. Where Natural Earth lacked a river I needed, such as the Bukhan in Korea, I drew a coarse main stem through the published coordinates of the government’s water-quality monitoring stations along it.

Height and ground from real measurements

Elevation comes from GEBCO 2026, a global height and depth grid at about 450 m, in its ice-surface version so that Greenland and Antarctica show the top of the ice. For each cell I keep only samples that fall on land, weight them by true area, and store the 10th, 50th and 90th percentile heights: about 1.1 billion samples in all. The median picks one of five bands, split at 200, 800, 1,800 and 3,500 m, and each band raises a tile by half a KayKit unit. Mountain props go only where the data shows a real peak: the high value above 1,800 m, at least 800 m between low and high, and the top well above the median. Flat plateaus stay flat.

The ground type joins two data sets. ESA WorldCover 2021 maps what covers the land at 10 m: trees, shrubs, grass, crops, bare ground, snow, wetland. It is too large to read in full, so I sample one native pixel in 128 on a fixed lattice, about 136 million samples from 2,651 tiles, and treat the shares as estimates. The Köppen–Geiger climate map for 1991 to 2020, at 1 km, adds tropical, dry, temperate, cold or polar. The rules are short. Mostly snow becomes ice; a polar climate becomes ice or tundra; mostly wetland stays wetland. A quarter or more tree cover becomes tropical, temperate or boreal forest by climate, and the tree share sets tree density. Dry climates become desert, dry grassland or dry shrubland by what dominates. The rest is grassland. A cell with no usable data stays unknown instead of being painted green, and Antarctica, which the land-cover data leaves almost empty, gets ice and bare rock from the SCAR Antarctic Digital Database.

KayKit tiles are coloured by an atlas: every face points at a flat swatch in one small texture. Swapping that texture recolours the whole set, so jungle, desert, tundra and snow need different atlases and a few tints, not new meshes. My first version gave each cell one palette, and climate borders were crisp hexagons. Now the terrain shader blends each pixel between the three nearest cells, with noise that bends the border and grows soft patches across it. The only new props are four I derived in Blender from the pack’s editable source file: two jungle trees, a sand dune and an ice cliff.

Hex-tile map of northern Egypt with sandy desert, the green Nile valley and branching delta, the Mediterranean to the north and the narrower Suez Canal to the east.
Egypt: desert on both sides, a green Nile valley and delta, and the Suez Canal drawn narrower than the river.

Wave Function Collapse, but only for height

Wave Function Collapse, WFC for short, is a constraint solver for tiles. Every cell starts with every tile it could hold. The solver repeatedly picks the cell with the fewest options left, chooses one, and removes every option nearby that no longer fits. At a dead end it steps back and tries something else. In Felix Turner’s version a state is a tile, its rotation and its height level, and neighbours fit only if their shared edge has the same type and the same absolute height. His demo solves about 4,100 cells in 19 hexagonal grids, each constrained by the borders of those already solved.

I had assumed WFC would draw my coastlines, but it cannot know where Gibraltar is. So coasts and rivers come from the steps above, and WFC solves the one problem that really is about local fit: joining land at different heights with slopes and cliffs. It gets seven land tiles, flat grass, two slopes and four kinds of cliff, so up to 131 states per cell with rotations and height bands. The solver is Felix’s code, pinned to one commit and run offline in Node, with small adaptations and a few hooks around it.

Diagram of the hex Wave Function Collapse rules for height, the solving loop and the window layout, above two real hex maps of the Altiplano edge comparing measured height bands with the solved slopes and cliffs.
The edge rule, the solving loop and the windows, with a real result from the eastern edge of the Altiplano below.

Three changes adapt it to a real planet. First, a preference: the solver tries the state whose edge heights are closest to the measured median first, and falls back only when it must. In a test area this cut the average height error at the top of each cell from 0.888 bands to 0.316, at about twice the solve time. Second, smoothing: a slope climbs only one or two bands, so targets near coasts and rivers are lowered to leave two transition cells per band. As a result every coast meets the sea at the lowest band; real sea cliffs would need new coast pieces.

Third, scale. The 1.06 million land cells are split into 1,189 connected patches, and large patches into windows: a 64×64 core with a 10-cell halo. Cells solved by an earlier window are pinned. If a window fails, the pinned cells in its halo are released once and it is solved again. Felix’s demo resolves its hardest conflicts by dropping a cell and covering the gap with mountains, which look intentional. I left that out, because on a map of real places a fake mountain range is a bug. A fixed seed makes the run repeatable, and an independent rebuild matched it byte for byte.

One failure sent me back into the solver itself. A patch of 1,520 cells kept failing even with 8,000 backtracking steps per try. On restart, the solver began without first applying the constraints it already knew, and walked into the same dead end. Applying them before each retry solved it on the second attempt. An independent check then walks every shared edge of the result: 60,809 river banks, 12,406 water joins, 31,069 joins with stock tiles and 6,212 height walls all fit.

Hex-tile map of the edge of the Andean high plateau, with grey-green highland and Lake Titicaca at the lower left, a forested drop, and dense tropical forest and a river to the right.
The same area in the viewer: the high plateau with Lake Titicaca at lower left, the drop to the lowlands, and tropical forest beyond. The river on the right is still held at sea level.

That river is the largest open problem. A raised river must flow downhill to its mouth, so the tools need proof of which way it flows, and the order of points in a Natural Earth line is not proof. Of 515 connected river systems, 354 have a height profile. The other 161 stay at sea level for now, and the land beside them dips to meet them. The hard cases are rivers that split into deltas or connect two basins, the way the Casiquiare channel links the Amazon to the Orinoco. HydroRIVERS records a downstream link for each reach, but only one, so it cannot describe a delta that splits. GRIT, which does map branches, allows only non-commercial use. Those systems stay flagged until I have evidence I can use.

The Great Lakes that were not there

For a while the map had no Great Lakes. I noticed only when I put it next to a satellite view at the same scale. Natural Earth’s land layer covers lakes as land; lakes are a separate layer I had never loaded. All 609 cells fully inside the Great Lakes were land, and so were Lake Victoria and Lake Baikal.

The fix was more than painting cells blue. Lake shapes come from Natural Earth’s lake polygons, and water levels from HydroLAKES, a global lake database with an elevation for each lake, or the surrounding shore height as a labelled fallback. Titicaca, at about 3,800 m, must sit at that height, not at sea level. The tools cut 1,355 lakes, reservoirs and salt lakes into the map, changing 36,284 cells, with shores that meet the land around them, islands inside lakes, and neighbouring lakes at different levels.

Two world-map captures of eastern North America side by side, the left without the Great Lakes and the right with the Great Lakes and many smaller lakes cut in.
Earlier world captures at the same scale. Left: before lakes were added. Right: after, with the Great Lakes and many smaller lakes cut in.

Lakes then broke rivers in a quieter way. Centre lines inside lakes had become river tiles on land, so cutting the lake out left channels that crossed the shore or ran beside the lake instead of into it. A screenshot of Lake Ladoga made it obvious. Eleven confirmed junctions, from Ladoga and Onega to Lake Taupo, now have the wrong channels removed and inlets rebuilt where the real river enters.

Drawing it in a browser

Until September 25 a Unity viewer drew the map. Since all the data came from my own tools anyway, I replaced it with a web viewer: three.js with its WebGPU renderer and node-based shaders, falling back to WebGL2. A converter rewrites the map into 32×32-cell chunks: a small table per chunk with each cell’s tile, rotation, height band and ground type, merged meshes for the 59,025 cells with custom geometry, and one library of 670 tile shapes.

The camera has a 20-degree field of view, tilts from 65 degrees close up to straight down when zoomed out, and keeps a hexagon of cells loaded around its centre, at most 77 cells in radius, or 18,019 cells. Stock tiles are drawn as instances, one batch per mesh. The sea is one plane. A worker computes a 512×512 map of distance to the nearest shore from the real tile shapes, and the water shader uses it for shallow colour, foam bands that follow the coast and river tints that fade into the sea. The 1,042,230 trees and rocks were placed offline by a port of the Unity placement code, with float rounding matched so JavaScript gives the same result.

Before retiring Unity I compared the two: in 89 test views the web viewer loaded exactly the same cells, grass brightness was within half a percent, and prop counts were within 1%. On desktop with WebGPU it runs at 60 fps. Moving one cell at the default zoom takes about 10 ms, plus 30 to 60 ms for the shore map in the worker, and a region seen for the first time takes up to about 0.65 seconds to load, 1.2 seconds fully zoomed out. Ambient occlusion, the soft shading where surfaces meet, left halos without a denoising pass, so it is off for now. Phones and online hosting are not tested yet; the converted map is about 410 MB.

Seasons and weather

Seasons and weather were built first in my fork of hex-map-wfc and then moved into the Earth viewer. Spring is the base look. Summer, autumn and winter swap the atlas only for grassland, temperate forest and boreal forest, tundra turns white in winter, and snow settles on upward-facing surfaces in temperate and cold regions. Jungle, desert, dry land and polar ground keep their colours, and the sun’s colour shifts with the season.

The same Rill & Reef coastline in winter, covered in snow with snowfall over the sea
The Stockholm coast in winter with snowfall. Only colour and light change; no tile moves.

Weather is clear, overcast, rain, snow or fog. Every option but clear dims the sun and shadows and adds haze that is thickest in low ground, so valleys fill first and peaks stay visible. Rain and snow are 6,000 and 4,000 particles positioned on the GPU from their index and the time. The fork also has temperature, rainfall and sea-level presets that reshape its random worlds; on the real Earth, climate comes from data, so only seasons and weather carried over. For now the season is one switch for the whole planet. The design calls for opposite seasons in the two hemispheres and local cycles such as the Amazon flood season, and that is still to come.

What I would do the same way again

  • Keep the data in charge. Let real data decide land, water, rivers and mountains, and let tile rules only connect them. Whenever a rule invented geography, it was wrong somewhere.
  • Decide shared things once. Voting on shared corners makes seams impossible instead of something to hunt down later.
  • Check the whole world, then look. Whole-world checks found the closed straits and merged islands. Only a side-by-side look at real imagery found the missing Great Lakes.
  • Pin and back up the data. Every source is checked against a stored hash. The generated map is not in version control and has been lost twice; a rebuild script and a local backup now restore it byte for byte.

What comes next

Next for the map: flow direction for the 161 unsolved river systems, better coverage where land-cover data is missing, and testing on phones. After that it gets what it is for: places to fish, and reasons to come back to the same shore in another season.

Credits. Tiles and props: KayKit Medieval Hexagon Pack by Kay Lousberg, CC0, including the alternate colour atlases and editable source of its paid edition, which carries the same licence. Tile rules, WFC solver, terrain palette and water texture: hex-map-wfc by Felix Turner, MIT. Data: Natural Earth (public domain); GEBCO Compilation Group (2026), GEBCO 2026 Grid; ESA WorldCover 2021 v200, © ESA WorldCover project 2021, contains modified Copernicus Sentinel data (2021) processed by the ESA WorldCover consortium, CC BY 4.0; Köppen–Geiger maps by Beck et al. (2023), Scientific Data; HydroLAKES v1.0 by Messager et al. (2016), CC BY 4.0; data from the SCAR Antarctic Digital Database, 2026, including British Antarctic Survey rock outcrop and coastline data, CC BY 4.0. The images are in-development captures and may change.