Autotile Explained: Why 47 Tiles, and What the Blob Rule Actually Is
Every time you place a ground tile in the Neta Studio 3D game builder, something has to decide which of several shapes that tile should be. A tile with no neighbours is a lone island. A tile with a neighbour to the east has one edge that should not draw its border. A tile with neighbours on both sides is a corridor. The moment you care about that decision, you are doing autotiling, and the moment you want it to be correct at corners, you run into the number 47. This post is about where autotile 47 tile blob rules come from, why the naive 16-tile model fails, and how to test a set you did not draw yourself.
The short version: a single terrain tile that must connect to its neighbours has more distinct local situations than most people assume. The 47-tile blob set is the smallest set that covers every situation a single terrain can be in, once you collapse shapes that are rotations or mirrors of each other, without leaving one-pixel gaps at diagonal contacts.
The naive model: four orthogonal neighbours, sixteen tiles
Start with the obvious design. A tile has four orthogonal neighbours: north, east, south, west. Each is either the same terrain or it is not. That is four bits, sixteen combinations, so you make sixteen tiles. This is the model most people build first, and it works fine for a long time.
The problem is what "not the same terrain" means. In the 4-bit model, a diagonal neighbour is invisible. The tile to the north-east is neither north nor east, so it does not exist as far as the bitmask is concerned. This is fine until two tiles of the same terrain meet corner to corner.
Picture a single tile of terrain at (0,0) and another at (1,1). No shared edge. Under the 4-bit rules, the tile at (0,0) sees no north neighbour and no east neighbour, so it draws a full rounded corner in the north-east. The tile at (1,1) draws a full rounded corner in the south-west. The two corners face each other across the diagonal. Because the art has to leave a little transparent padding outside the border to avoid bleeding, and because the border itself is drawn inset, the two corners do not quite touch. You get a one-pixel diagonal seam of background terrain running through what should be a solid mass.
This is the classic 4-bit failure. It is not a bug in your renderer or your atlas. It is the model itself being under-specified. The tile genuinely needs to know about the diagonal, and the bitmask does not carry that information. Every project that ships a 4-bit set eventually patches this by hand-drawing a few corner-filler tiles, at which point the "sixteen" is a lie and you are maintaining an undocumented hybrid.
The 8-bit corner model and the collapse to 47
The fix is to include the diagonals. Each tile now looks at all eight neighbours: four orthogonal, four diagonal. That is eight bits, so 256 combinations. You do not want to draw 256 tiles. Most of those 256 are the same shape.
The question is how many distinct shapes there actually are. Two tiles are the same shape if one can be transformed into the other by rotating or reflecting the tile. A square tile has the full symmetry group of the square: four rotations, and a reflection, giving eight symmetries. If you take the 256 states and merge every state that is a symmetry of another, you do not get 256/8 = 32. The division is not clean because many states are already symmetric under some of those transforms — a tile with all eight neighbours filled is its own mirror image, a tile with only north and south filled is symmetric under reflection and under a 180-degree rotation. The Burnside-style collapse of the 8-bit blob set lands at exactly 47 equivalence classes.
That 47 is the answer to "how many distinct shapes does a single terrain tile need." It is also why the term autotile 47 tile blob rules keeps showing up whenever people discuss this in engines, because the number is stable across implementations. Tiled, Godot, and Unity all arrive at the same figure from the same argument.
The 4-bit model, collapsed the same way, gives far fewer distinct shapes and is why 16 feels tidy. The 8-bit model gives 47 and is why 47 is the number that shows up in real terrains.
Why the two diagonal bits get masked
Here is the part that catches people when they write their own bitmask code. You have eight bits, you look up the tile, and you get the wrong shape at concave corners — the inside corner where three tiles of the terrain meet in an L.
The rule is: a diagonal neighbour only matters if both adjacent orthogonal neighbours are also the same terrain. If the tile to the north is a different terrain, then the north-east diagonal is irrelevant — there is no continuous surface for that corner to be concave against. Worse, if you leave the bit set, you select a tile that draws a filled corner where it should draw an open edge, and you get a hard-edged square nub sticking into the gap.
So the assembly step is: take the eight neighbour bits, and for each diagonal, mask it out unless both of its orthogonal neighbours are set.
- North-east bit survives only if north and east are both set.
- North-west bit survives only if north and west are both set.
- South-east bit survives only if south and east are both set.
- South-west bit survives only if south and west are both set.
The masking step is where almost every hand-rolled autotiler breaks. You get the diagonal bit right, you get the rotation lookup right, and you forget to gate the diagonals on the orthogonals. The symptom is a single square nub at every concave corner, and it looks like an art problem, not a code problem, so people redraw the tiles. The tiles were fine.
The masked bitmask then goes into the lookup. With the masking in place, the number of reachable states drops: the four "diagonal set, both orthogonals clear" states become impossible, and a few others collapse. What remains maps cleanly onto the 47.
What the 47 is actually counting
People read "47-tile blob set" and picture 47 separate images in an atlas, each a full tile. That is not quite what it is, and the misreading causes a lot of wasted work.
A 47-tile set is really 47 roles a single terrain plays. Each role is a corner variant, an edge variant, or an interior fill. Consider the interior of a large mass of terrain. Those tiles are all identical — pure fill, no border. The 47 is counting the border and junction configurations, not every cell. If you export your set as a full atlas with one image per role, you get 47 images, but many of them are the same fill with different rotation applied at draw time.
This matters for two reasons. First, if you are authoring art, you can draw far fewer source tiles and produce the 47 by transform at build time — see the generation section below. Second, if you are debugging, you should not expect to see 47 distinct-looking tiles in your atlas. Expect a much smaller number of visually distinct border pieces plus a lot of index bookkeeping.
Model | Neighbours considered | Raw states | Distinct shapes after symmetry | Fails at |
|---|---|---|---|---|
4-bit | N, E, S, W | 16 | Few | Diagonal-only contact leaves a one-pixel seam |
8-bit blob | N, E, S, W, NE, NW, SE, SW | 256 | 47 | Nothing, if diagonals are masked correctly |
8-bit, unmasked | All eight | 256 | 47 reachable plus invalid | Concave corners render a solid nub |
The table is the whole argument in three rows. The middle row is the set you want. The bottom row is what you get if you skip the masking and try to use all eight bits directly.
How the engines name the same set
The 47 shows up under different names, but it is the same object.
In Tiled, terrain sets are configured with a "corner" or "edge" layout, and the editor exposes the blob lookup for 8-bit. The Wang set terminology in Tiled is close to this: Wang tiles count edge and corner colours, and a two-colour corner-and-edge Wang set is the 47 in different clothes. If you are importing tilemaps into the Neta Studio 3D game builder, the blob set you build in Tiled maps onto the terrain roles you assign in the world.
Godot's terrain system uses the same 8-bit model and lets you paint with a terrain, then resolves the tile per cell at runtime from the neighbour bits. Godot distinguishes between "match corners" and "match sides" in the terrain modes, which is exactly the orthogonal-versus-diagonal question from earlier; enabling both is what gets you to the blob set.
Unity's rule tiles take a different surface form — you author a set of rules, each a pattern of neighbour conditions — but the underlying coverage is the same. A complete rule set that handles orthogonal and diagonal neighbours without gaps is, by the same counting argument, the 47.
The names differ but the lookup does not. If you port a terrain from Tiled to Godot to Unity and the corners break, the cause is almost always that one system counts the diagonal as a neighbour and the other does not in that particular mode. The art is portable. The mode setting is not.
Generating a set instead of drawing one
You can draw 47 tiles by hand. People do. The cost is that any change to the terrain's border style means redrawing all of them, and any mistake in the set is a mismatch you only see when you paint an awkward shape.
The alternative is to generate the set from a small source. The recipe:
- Draw one tile per axis-aligned border case. You need a fill, a straight edge, an outer corner, an inner corner, and their variants. That is a handful of source images, not 47.
- Define the border for each of the four sides as a stroke, a bevel, or nothing, driven by the masked bitmask.
- At build time, compose the 47 by combining the side strokes and corner pieces per role, applying rotation and reflection as needed.
- Export the result as an atlas with the role index baked into the tile ID, so the runtime lookup is a single array read.
This is the path the Agent Sprite Forge tooling is built around: you describe the terrain, it produces the source pieces and the index, and you get a set you can re-generate when the art changes instead of re-drawing.
Generate, do not draw, once you have more than one terrain. The moment you have grass, stone, and sand, hand-drawn sets triple the maintenance and the 47-count means the drift between them is invisible until you paint a junction where all three meet. Generated sets stay consistent because they come from the same rules.
Testing a set with an awkward shape
A 47-tile set can look correct on a big square and fail on a shape with concave corners. Do not trust a set until you have painted a shape that exercises every role.
The plus-sign is the standard test. Paint a plus: a centre tile with four arms, each one tile wide. Every arm connects to the centre on one edge and terminates at a tip. The plus exercises the straight edges, the outer corners at each tip, and — critically — the four concave corners where the arms meet the centre. If your diagonal masking is wrong, the concave corners show the nub. If your 4-bit model is sneaking in somewhere, the four inner corners show the one-pixel seam.
The one-tile tunnel is the second test. Paint a corridor one tile wide and several tiles long. This exercises both the longitudinal edges and the ends, and it catches sets that handle corners but not long straight runs with a border on both sides. A set that fails here will show a doubled or missing edge line.
In the Neta Studio 3D world builder, the same tests apply in three dimensions: paint a one-tile-wide bridge and a plus-shaped platform, and look at the inside corners where the arms join. This is also how The Cyclops' Island and Mini World terrain is checked — the awkward shapes get painted before the terrain is declared done, not after.
Where this leaves you
The 47 is not a magic number and it is not an arbitrary limit. It is the count of distinct local situations a single terrain tile can be in, after you account for all eight neighbours and collapse the rotations and reflections that produce the same shape. The 4-bit model loses the diagonal and gaps at corner contacts. The 8-bit model carries the diagonal, but only if you mask the diagonal bits on the orthogonals, or you trade the gap for a nub. Get the masking right and the set works in Tiled, Godot, Unity, and the Neta Studio 3D game builder without changing the art.
Draw fewer source pieces than 47, generate the rest, and test with a plus-sign and a one-tile tunnel before you ship. Those two shapes find the two failures that the big square never will.
Keep going
Build the world it goes in
A tileset is a material with nowhere to stand. Every world on the 3D game builder was made from one written description and published as a page you can play — including The Cyclops' Island and Mini World.
