I am looking for any input on simulating water in 2D, against a rather large (call it) blocked/not blocked array (viewed from the side). I have come up with the following ideas:
Cell Automata
Do a massively parralel simulation on the CPU, using cell automata. With rules as simple as:
- If there is a cell open to the bottom move to it.
- Check the left and right cells, choose a random one out of the two and move to it.
Pros
- Simple to implement.
- Meaningful/deterministic in a multiplayer system.
Cons
- Probably really slow.
- Not convincing.
Fluid Dynamics on the GPU
Perform a rough approximation of fluid dynamics on the GPU against a texture like the following:
+------+-----+-----+-------+
|R |G |B |A |
+------+-----+-----+-------+
|vX |vY |NULL |Density|
+------+-----+-----+-------+
Pros
- Probably really fast.
- Could be quite convincing.
- A further pixel shader could render it directly.
Cons
- Difficult to implement.
- Difficult to tweak.
- I can't allocate a single texture the size of my level.
- I could overlap the grid areas, but this would add further complexity.
Particles
Use particles to simulate the water. During rendering using additive blending and then apply a multiplication function to the alpha channel to give the water crisp edges.
Pros
- Will probably look nice.
- Easy to implement.
- Easy to render.
- Meaningful in a multiplayer system, although would require quite a bit of bandwidth to transfer.
Cons
- Inter-particle effects will probably be slow (neighborhood lookup).
- Could lead to water 'leaking' through solid spaces (because the solid space is small, e.g. 1px).
- Could lead to strange holes in the water depending on the particle size.
- Both of the above could be mitigated by allowing particles to drift closer together than their real size, however would cause problems with the inter-particle and particle/landscape performance.
Any further ideas?
Note: This is an approximation, I am not looking for physically correct water here - just something that 'is good enough' (bonus points for quick and dirty). The game is multiplayer, so unfortunately the whole level needs to be simulated continuously.