Implementing Auto Tiling with Just 5 Tiles(kyledunbar.dev)
60 points bytodsacerdoti5 days ago |9 comments
Lerc2 minutes ago
This is essentially https://en.wikipedia.org/wiki/Marching_squares with right angles, isn't it?
fredrikholm6 hours ago
Tiling sprites is a wonderful example of something that starts off relatively simple and then explodes into all kinds of interesting headaches.

In the beginning, you're looking up a set of UVs in a table indexed by some mask value.

In the end, you're debugging errors where one off by one error cascades into strange realms of indexing the wrong (unloaded) chunk with coordinates rolling over to positions that make no sense, looking up neighbours that look one way yet you end up drawing something completely different.

The suggest solution is an elegant and relatively common approach to what would otherwise be a naive series of nested 40+ if statements consisting of much swearing and sprite editing.

zahlman4 hours ago
There's a lot of explanation here but ultimately this is basically just the standard 16-tile set except assuming you can use rotations to deduplicate and don't need to allocate a tile for empty space. The latter makes sense for platformers (since your tiles likely represent objects that are supposed to be floating over some other background drawn another way) but not so much for, say, RPGs. (And the rotated tiles are often not great in RPGs, either.)
1313ed013 hours ago
Tiled has some mode where you can paint the tile corners or/and edges to automatically insert tiles. When using only the corners to paint (and only a single terrain type) that would be equivalent to shifting the visual grid by a half tile trick, if I understand correctly?

Adding multiple types of terrain and also making it possible to paint the edges of course will add an explosion of possible tile types that are required. Looks like there is support in Tiled for optional automatic mirroring or rotations to add missing tile variations.

https://doc.mapeditor.org/en/stable/manual/terrain/

krapp3 hours ago
> Looks like there is support in Tiled for optional automatic mirroring or rotations to add missing tile variations.

Tiled uses tile "Global IDs" that encode booleans for flip and rotation into the upper bits: https://doc.mapeditor.org/en/latest/reference/global-tile-id...

It's kind of a pain in the ass to implement IMHO because you need to strip these bits and iterate all of your tilesets to find the correct tileset and tile for the GID for every ID (which is what the tile layers actually store) but a lot of the inherent performance issues can be improved upon by caching the last result, since consecutive tiles in a tilemap are likely to repeat.

Also I found this page useful: https://eishiya.com/articles/tiled/

aezart1 hour ago
I've never been a fan of dual grid, and personally prefer the rpg maker approach of using 5 sample tiles and then chopping up and recombining them to make the 47 tiles needed for what I believe is called "blob tiling".
bulgur9996 hours ago
The low tile count simply comes from applying the dual grid approach popularized (if not invented) by Oskar Stålberg to a specific 2d perspective where tiles can be generated through rotations and/or flips.
swiftcoder3 hours ago
Oskar does both rotations and flips to his 3D tiles, albeit only in 2 dimensions. He uses basically the same set of 5 tile shapes for any tiles that don't need to take into account verticality (i.e. look at the beach tiles in Bad North)
bArray6 hours ago
Dwedit2 hours ago
Does anyone know the history of auto-tiling in games? I know that Dragon Quest II (1987) had this feature for water tiles on the overworld, before it got backported to the North American version of Dragon Warrior 1.
HugoDz5 hours ago
Very cool! Sprite Fusion maker here :)