Water simulation with a grid
Asked Answered
E

5

8

For a while I've been attempting to simulate flowing water with algorithms I've scavenged from "Real-Time Fluid Dynamics for Games". The trouble is I don't seem to get out water-like behavior with those algorithms.

Myself I guess I'm doing something wrong and that those algorithms aren't all suitable for water-like fluids.

What am I doing wrong with these algorithms? Are these algorithms correct at all?

I have the associated project in bitbucket repository. (requires gletools and newest pyglet to run)

Ebonize answered 17/2, 2009 at 9:26 Comment(0)
C
7

Voxel-based solutions are fine for simulating liquids, and are frequently used in film. Ron Fedkiw's website gives some academic examples - all of the ones there are based on a grid. That code underpins many of the simulations used by Pixar and ILM.

A good source is also Robert Bridson's Fluid Simulation course notes from SIGGRAPH and his website. He has a book "Fluid Simulation for Computer Graphics" that goes through developing a liquid simulator in detail.

The most specific answer I can give to your question is that Stam's real-time fluids for games is focused on smoke, ie. where there isn't a boundary between the fluid (water), and an external air region. Basically smoke and liquids use the same underlying mechanism, but for liquid you also need to track the position of the liquid surface, and apply appropriate boundary conditions on the surface.

Couldst answered 1/5, 2009 at 3:43 Comment(4)
The source for Stam's code (Jos Stam, "Real-Time Fluid Dynamics for Games", CDROM download) is still uploaded & working here. That zip has also been put into the web archiveSubinfeudation
.@Couldst The boundary between the air and the smoke should be the same idea as the boundary between the surface of the water and the air. Stam's code actually has a parameter for viscosity (visc). If you play around with it, I'm pretty sure you could repurpose that smoke code for fluidsSubinfeudation
The issue is that smoke is generally represented as a continuously varying density field, without any distinct "surface", whereas liquids do have a sharply defined boundary between interior and exterior. Now, one can certainly repurpose the density field from smoke as a smooth geometric approximation of the surface -- example techniques are level set methods and volume of fluid methods. However, doing this involves fairly invasive changes to the simulator. Additionally, you don't actually want to simulate velocities for the "air" region in a liquid simulator.Couldst
While I'm here, I can mention that in the 15 years since my post above, a couple more books have come out: "Fluid Engine Development" by Doyub Kim and "The Art of Fluid Simulation" by Jos Stam. Fluid Engine Development also has code associated with it, so that may be useful: fluidenginedevelopment.orgCouldst
J
2

What type of water are you trying to simulate? Pools of water that ripple, or flowing liquids?

I don't think I've ever seen flowing water ever, except in rendered movies. Rippling water is fairly easy to do, this site usually crops up in this type of question.

Jut answered 17/2, 2009 at 9:50 Comment(1)
flowing liquids, rippling pools are quite trivial, even though cool and I'd know how to simulate those already. :>Ebonize
S
2

Cem Yuksel presented a fantastic talk about his Wave Particles at SIGGRAPH 2007. They give a very realistic effect for quite a low cost. He was even able to simulate interaction with rigid bodies like boxes and boats. Another interesting aspect is that the boat motion isn't scripted, it's simulated via the propeller's interaction with the fluid.

Cem Yuksel's Wave Particles
(source: cemyuksel.com)

At the conference he said he was planning to release the source code, but I haven't seen anything yet. His website contains the full paper and the videos he showed at the conference.

Edit: Just saw your comment about wanting to simulate flowing liquids rather than rippling pools. This wouldn't be suitable for that, but I'll leave it here in case someone else finds it useful.

Skill answered 1/5, 2009 at 4:15 Comment(0)
A
1

Yeah, this type of voxel based solution only really work if your liquid is confined to very discrete and static boundaries.

For simulating flowing liquid, do some investigation into particles. Quite alot of progress has been made recently accelerating them on the GPU, and you can get some stunning results.

Take a look at, http://nzone.com/object/nzone_cascades_home.html as a great example of what can be achieved.

Antinode answered 17/2, 2009 at 10:11 Comment(0)
S
0

To do water, you'd probably want to adapt Jos Stam's fluid demo to 3D

Mike Ash has a blog entry that describes how to bring Jos's demo to 3D (full source)

There is a github implementation of Mike Ash's code here

Some mods to that demo got me this:

water using mods of Jos Stam's fluid demo

A quirk of that sim is if you put force from empty voxels (nothingness) into the fluid, the fluid tends to disappear into nothingness

But if you put a force from inside the fluid, outwards towards empty voxels, the fluid tends to expand and become more

To make the water fall downwards (without completely dissipating right away), you have to put the downwards force inside the voxels that contain the fluid

If you put a downwards force across the entire voxel grid (as I first did), the fluid will tend to just disappear into the bottom of the container (no matter what you do to the boundary conditions), because of the quirk I mentioned above

Subinfeudation answered 23/4 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.