I have a heightmap downloaded from a GIS database that is 512x512 pixels per tile. How do I map this correctly to a 513x513 Terrain heightmap programmatically?
I have tried various approaches, like simply scaling the 512x512 heightmap to a 513x513 heightmap, but always end up with small gaps between the terrain tiles.
Answering my own question. Really dumb issue caused by poor documentation, and googling it just pointed to people who were even more confused and came up with all kinds of voodoo solutions, like “just mess with the settings until it looks OK”. Or some long winded code that concluded that it will ALMOST fix it. Christ…
The solution for gap free tiling:
So, I wrongly assumed tiles of say 513x513 would contain unique data at every height point, but nope. 512x512 part of it is unique, the remaining 1 pixel border SHARES data with 2 bordering tiles, and is ONLY used for a smooth transition. Or there will be a gap when there are large height differences at the edge. The terrain edges has exactly the height of the border height data, So two tiled terrains next to each other must have the exact same height at the border, or the same border would have two different heights. Hence the gap-.
So, don’t scale the data, just plug in an extra pixel at the right and bottom border (for example) from the bordering tiles.
Also, make sure the tiles are autoconnected, to ensure they are tesselated like one large unity to avoid even more gaps…