Shrinking water flow after a flood
(Originally posted on Mastodon)
Testing ideas for my fluid simulation system. The data structure to represent liquids in memory stores horizontal liquid slices, which are simply slices of 1m height that can have any shape seen from the top, encoded as an image with 1 bit per pixel.
As liquid quantity increases, a slice can grow lateraly (if not blocked by surrounding terrain), to simulate spreading of the liquid.
What wasn’t implemented yet is, if the liquid quantity decreases, then the slice should shrink.
Here is my attempt so far. It works quite well in this simple case. It still has the issue that the final shape is a bit random, and growing/shrinking cycles will potentially result in different shapes each time.
This idea doesn’t work that well when there is a loop somewhere though. And, again, the problem that the resulting shape doesn’t necessarily make sense. This could probably be improved by using terrain height (removing pixels that are at a higher altitude first, so that in the end the path follows the lowest altitude).
But after playing a bit with this idea, I came to the conclusion it won’t give good results. A bit sad because it was simple and could have a very efficient implementation.
Here is the result in the game. And it creates quite a mess. I’m really not satisfied.
My next idea is a “reshape” algorithm, that will find the shortest path from input to output (also favoring lower altitude), and then spread that path as much as required to get the desired thickness. However this could become costly for big slices.
After implementing this idea, the simulation works much better ☺️
Arguably, it looked interesting before too, but the result was unpredictable, and completely different before/after a flood.
The new version produces a much more reasonable river bed after the flood. It does leave a few puddles here and there, but that’s not a problem, I can add an evaporation system to make them go away after some time.