I’m not very experienced with water generation in procedural worlds, and was hoping someone experienced could figure help.
In my 2.5D world, generation is based on a noise height map with separate biomes. Each biome has different textures generated at different levels, and maybe some different ordering of generation. Additionally, the height map changes between biomes, but the general noise is the same(think of it as multipliers and mesh curves changing). Currently, there is a water texture to take the place of actual water in the world, but at chunk edges, the texture may just fade upwards or downwards, which isn’t very realistic.
Is there a way to procedurally generate water so that the height of a certain pocket of water is the same but it isn’t just one big plane underground that is constant throughout the entire world? Such as local water levels in deserts being on average lower than that of marshes, etc. However, I want to avoid the water box/plane ending abruptly or sloping downwards/upwards at certain points between chunks or something.
Does anyone have any experience with this?
I think I may have a solution, setting a constant height for water generation per biome, we can then go through all the points in a chunk where it is under the height but borders one over it(an edge), and attempt to flood-fill the edges(through all the chunks). The time complexity, on this, is around O(P*N) where P is the perimeter length and N is the side length of a chunk. This is because we also need to initialize the data for any new chunk we enter upon generating the terrain. To give a reference of scale if the side length of a chunk is 100 and we want to complete the math in under a second, we can get an area of as much as 80 billion units(the resolution of your water). This calculation goes down with chunk size, up to an area of ~8^14(under a second). One may also set a maximum perimeter count.
A chunk would fail to create a body of water if the perimeter intersects with already generated chunks or the perimeter is too great. If it fails, you either could not generate water at that position/half the water height and retry generating. We can test if a water body is inside another through the “point in polygon” algorithm, but I haven’t found a way find if a perimeter contains no bodies of water.
I want to illustrate that though this needs the perimeter generation all at once, the algorithm is powerful enough. If you are indeed creating a voxel game with a resolution of up to a voxel, you can create a body of water up to an area of 10^12 in under a second, which is more than a 3*3 of Minecraft worlds.