Placing buildings on uneven terrain

In Empire of Ember we allow the player to build their own cities on uneven terrain. The problem, though to a lesser degree than in the screenshot, is there can be gaps between the building and the ground.

We fix this by finding the bounds of all the colliders of the building, then leveling the terrain to match those bounds.

As you can see in the screenshot, this creates sharp edges.

To fix this we:
1. Create a new heightmap texture in memory. The new heightmap texture is the same as the original heightmap, except where buildings touch the height is the base of the building. In addition, the bounds of the base of the building are increased by the pixel radius of the blur effect to be applied. This is to prevent the blur from changing the height of the terrain under the object itself.
2. Create a second interpolation texture, where 0 means the original terrain and 1 means the increased bounds of the object was touching the terrain.
3. Blur the two textures.
4. Linearly interpolate between the original heightmap and the new heightmap, based on the interpolation texture.

Final result

Leave a Comment

Your email address will not be published. Required fields are marked *