I've started looking for an algorithm to generate underwater heightmaps.
Currently the game generates it by randomly lowering all vertices related around water tiles before starting the game (in map.cpp/mapLoad() function). This lowering is relative to the map's heightmap terrain, of course, so we can still make things like mountain lakes or waterfalls.
What i'm trying to do is make this random algorithm a bit more clever and sensible. The easiest idea i had so far is to make the seabed smoothly deeper when far from the coast and shallower near the coast. The result is shown on the screenshot below. I'm not yet posting code because it's a bit rusty. I'm still adding some random noise to it.
Now, what i'd really like to see is a fractal seabed generation, which will give us a varied realistic underwater terrain as we see in seas. Not sure it's necessary, and not sure what exactly is realistic, but it'd be great if somebody comes up with any effective solution.
What we need to code is a function that will lower the seabed. It has access to all vertices of the map (by vertice i mean a common vertice of any 2x2=4 adjacent tiles) and knows whether a certain vertice is to be covered by water; it needs to calculate new heights for all water tiles.
Something like this:
Code: Select all
// produces a dull flat seabed
void generateSeabed(void) {
int i, j;
for (i = 0; i < mapHeight; i++)
for (j = 0; j < mapHeight; j++)
if (isWaterVertex(i, j))
mapTile(i, j)->height -= 100; // we refer to the tile, but mean its top-left vertex
}