How would you program a liquid?

Started by
17 comments, last by Platinum314 20 years, 9 months ago
I think the modelling using particles that represent volume would be very problematic to get running at any sort of real-time speed. The other alternative could be to instead model the surface of the water. The surface would take the form of a web of particles. For practical applications the number of particles would be variable. Now some of the surface is static and is up against the walls of a container. Other surfaces will be dynamic, assuming equilibrium isn''t reached.

The volume will be predetermined and constant. So each frame the volume is calculated. I haven''t put much thought into this, but if there isn''t a better way, an octree will work fine. If the volume is too small, then a force is exerted on the dynamic surfaces to increase the volume, this is in addition to the force due to gravity.

This should allow the water to flow. If some surfaces come into contact with each other, different shapes could be formed, such as one equivalent to a donut and not a sphere. If it breaks apart completely, a new mass of water is formed.

This is the best approach I can think of. It''s complicated and above my programming level, but I think it should work. If it is a viable model, then I''m sure someone will have documented it somewhere, if not then there''s probably a better way.
Advertisement
I think a question needs to be answered before the "right" approach can be arrived at: What do you want the fluid simulation to be able to do?

Will it be Y-simple (restricted to height-map like shapes)? Will it be able to crest up into waves? Can it build up? Can it spray or splash? Will objects be able to push the liquid? Will it handle temperature? Will you be able to handle viscosity? Will it work regardless of the terrain/environment or will you need to restrict it to a simple terrain? What kind of system specs will it run on, how much of the CPU will be free at that point, how much RAM, how fast does it NEED to run?

These are the kinds of questions that you will need to answer before you can decide on an appropriate model. The model I suggested handles all of these because that''s what I''m interested in. But what do you want to do with it?
Thanks for all of the tips and links.

I was thinking about the idea of only using particles for the surfaces, but that doesn''t solve all the problems, such as if I wanted to fill a cup with a liquid and then dump it somewhere else. I was also thinking of using real-time transforming multiplying polygons, which is probably my best fit so far.

Anyway I wasn''t really planning to program any of this into a game, unless it is a limited liquid simulator in a predefined enviroment.
The sentence below is true.The sentence above is false.And by the way, this sentence only exists when you are reading it.
risking that my post is useless I´ll tell you what I´d try:

assume you liquid has a uniform density (you won´t be able to send sound waves through it besides some other problems that might occur). The behavior of the liquid should be entirely given by it´s surface (since for every point within the surrounding looks equal). Start with a sphere (form of least surface tension for a given volume) of liquid and lay a grid of equidistant points over it. Then apply the physical laws of your world to each of the gridpoints and take into account the forces applied to a point by it''s neighbours (surface tension). You should be able to fill a cup of coffee this way though the calculations propably won´t be simple. Problems that might occur is that when your fluid splits up in two entities you have to rearrange your neighbours.
quote:Original post by Sneftel
Fluid dynamics simulations are incredibly processor-intensive. They run on supercomputers, for days at a time, with hundreds of processors and terabytes of RAM. It is not a good thing to try to do in a game engine.

How appropriate. You fight like a cow.


At the extremes, where you''re calculating shock/boundary-layer interactions in turbomachines for aircraft engines, or for fighter-jets at the extremes of their flight envelopes, yes. But as with every other type of physics there are a huge number of simplifications ranging from things that run on supercomputers for days at a time to things that take hours on a normal PC to minutes on a PC to fractions of seconds on low-powered machines.

Case in point. Jos Stam of Alias Wavefront two years ago at the SIGGRAPH conference demonstrated real-time interactive fluid dynamics running on a Compaq pocket PC (XScale processor). I repeat, 2 *YEARS* ago on a PDA. Probably only achieved 10fps, and it was a 2D only simulation but that''s a far cry from days on a supercomputer, n''est-ce pas?

Jos'' work is a good place to start, as he has a stable, simple-to-code algorithm that works in 2D and 3D. It has limitations, but its a good place to start. I''d also highly recommend looking at Jeff Lander''s work. He developed a similarly simple technique that allows you to simulating flowing rivers that, with some work, can overflow their banks, create splashes, etc. In real-time.

Some reference material:

see the "Taming a Wild River" link

Jos Stam''s SIGGRAPH 2001 paper that contains a demo of real-time fluids on a Pocket PC



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Thanks for the really neat stuff. That link to the Pocket PC Real-time fluids.

The hardest part about liquids I think is the fact that they can split or combine into different volumes. Yet this is one of the most important properties.
The sentence below is true.The sentence above is false.And by the way, this sentence only exists when you are reading it.
Use a Pixel Shader (like in Morrowind)
Anonymous: He wants to be able to model the behavior of a liquid, not just render it...
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
I''ve never tried to simulate liquid before but it seems to me you can use a particle system if you use very large particles.

This topic is closed to new replies.

Advertisement