(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.

A top view of a "liquid slice". It's just a few white pixels over a black background. There is also a green area (representing liquid input) and a red area (representing liquid output). The video shows a "tick" button, which gets repeatedly clicked. Each time, the slice shrinks, showing fewer and fewer white pixels, until only a thin path remains connecting the green area to the red area.

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).

Similar video, but this time the white area has a small hole (a black pixel). As the "tick" button gets clicked, this hole increases in size, and in the end the path from the green to the red area has junction with two possibilities.

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.

Screen capture of the 3D green mountainous terrain under a blue sky. There is a dam retaining a pool of water. The player digs a hole in the dam, releasing the water, wich rushes down the slope over a large area. Once the wave has passed, water recedes but leaves a weird maze of lines of water behind.

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 ☺️

Again a screen capture of the 3D green mountainous terrain under a blue sky. There is a dam retaining a pool of water. The player digs a hole in the dam, releasing the water, which rushes down the slope over a large area. Once the flooding wave has passed, water recedes to a thinner river bed.

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.