Water Simulation

Started by
6 comments, last by grhodes_at_work 17 years, 7 months ago
Hi We are planning a new RPG, which intruduces some inprecedented gameplay features. One among them is using physically correct water. It's able to flow, interact with other object, etc. This allows to do quite interesting things: fill pits, then turn water into ice and move on it; or fill pits during rain; or make a whole in wall with strong water flow; and many more... But it requires physically based water simulation. So, have anybody tried to implement such thing, or it's possible, that someone have thought about it or has interesting papers, links? What can you recommend, suggest? Any information on topic would be useful. PS: I hope, that my poor English doesn't hide my thoughts ;)
Advertisement
That's quite the task you have ahead of you.

A quick google for particle based fluid simulation yields this paper (.pdf), which looks decent.

This paper (again, a .pdf) may also be useful.
That a big project to say the least. Stability and speed is probably going to be your worst enemies. Anyway I have seen some a nice demo including sources here on GameDev. However I don't have the link to the thread that contains the link to the webpage in question. Try searching for it using SPH and particle fluids and you should find it. It should at least give you a good start.
Plane9 - Home of the free scene based music visualizer and screensaver
ok, i only know one concept:

the basic idea is, to divide the water into cells, each cell has some attributes like pressure. so every cell looks in their neighbourhood, what pressure they have. so high pressure move to low pressure and so on.

most games only simulate the graphic of water (approximations), so what you are planning needs a lot of cpu power.
(thats why fluid dynamics are often calculatet on clusters)
Depending on the end result you want you might be able to get away with a more macro-level approach to water simulation. For example for the case of pits filling with water, if you know the dimensions of the pits and the rate at which its raining you can easily calculate the rate at which the they accumulate water and update your water surface level for each pit accordingly without having to model flows. Or for the case of a hole in a dam, if you know the height of the water surface level above the hole and the dimensions of the hole itself you can easily calculate the 'ejection force' using simple formulae from which you can calculate the ejection distance, curvature, etc, again all without having to model complex flows.
[size="1"] [size="4"]:: SHMUP-DEV ::
If you need free flowing water and have any form of larger area this water can move through then you should use SPH (Smoothed particle hydrodynamics). Basicly just particles that acts like drops of water. Using the grid based approch would take up way to much memory in 3d and also the cpu usage would be high. Also you would need to track the fluid boundaires (That is the air-water) using markers and thats another headace. All this is a lot simpler using SPH. A good marching cubes and you have that part fixed. Also because it's particles you will only calc the parts that you actually use. In the grid based version you need to calculate everything (Well unless you using some form of sparce grid solver) even if there isn't any fluid in the cell. However SPH has it's shear of problems but for games that want to use free flowing fluid the only way to go is SPH. If for now other reason so because of the memory usage.
Plane9 - Home of the free scene based music visualizer and screensaver
You have three methods:

1. Full 3D simulation using grid methods. This will allow for splashing etc, but is difficult to get robust (e.g. just conserving fluid quantity) and likely to be slow.

2. Full 3D sumulation using particle methods. You can trade off quality with performance with this, and will handle splashing etc. It's slow for large volumes (you could probably handle 2000-10000 particles, depending on your CPU budgets - remember the more particles the more rendering time too).

3. 2D surface (heightfield) simulation. Really cheap (in comparison to the 3D methods above) and suitable for medium-large expanses of water. Also relatively easy to render. However, it won't handle splashing/pouring etc. You can add some visual effects with very simple (non-physical) particle effects on the surface.

My inclination would be to experiment with a combination of 2 and 3. E.g. if you have a buck of water and an empty bath - initially the water in the bucket is simulated using a heightfield method (quite tricky, since the boundaries/depth will change as the bucket moves, but doable). Then when the bucket is tipped enough, particles get spawned to simulate the flowing water, and the parameters of the heightfield water in the bucket get changed (to conserve mass). Eventually the bucket becomes empty, and that heightfield simulation gets deleted. When the flowing water hits the bath this enables a heightfield simulation there, and somehow(!) the particles convert to the heightfield parameters - to conserve mass. The particles hitting the bath/water surface will stay as particles until the stop splashing.

Rendering the flowing/particle fluid could be done using a surface reconstruction (marching cubes) or maybe a billboard approach would look good enough.

I think that the old PS3 ducks in a bath demo from a year or so ago (actually, where they used eye-toy or something to scoop water up from a tub into a small container, and pour it out again, IIRC) probably used this combined method - but that's just a guess.

Edit: I have a 2D SPH demo, including source code. Also, the Ageia SDK supports liquid simulation (including interaction with rigid bodies), and maybe that would be fast enough, if your game required their PPU board...
Jeff Lander presented a simple technique at GDC a few years ago, that supports relatively large expanses of water that can gather into pools, etc. Simple rules could be added to create some icing type effects, and he describes an approach to simulate (or at least visualize) splashing. He hasn't made his implementation available, but you can find his presentation at the following link:

Taming a Wild River

Jeff's approach is quite similar to MrRowl's recommended approach. I attended the presentation, and it can work nice in practice, though you'd have to implement some advanced rendering techniques to get finer details on the water surface.

Jeff's GDC presentation page as a whole is here:

Developer Conferences Companion Page
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement