Particle-Based Fluids

One of the subjects which captured my imagination several years ago, when this subject started to hit professionally-authored CGI content – movies – was how fluids could be emulated graphically. And the state of the art is such, that particle-based fluids can be rendered on high-end, consumer graphics cards, where the particles’ motion is defined by density, pressure, and resistance to compression.

Sadly, I still see no place where consumer devices can simulated fluids as volumes yet – and do so in real-time.

But once the software has been set up to compute the positions of swarms of particles, which collectively define a fluid, a logical question which the power-user will ask is, ‘Now what? A surface of water reflects and refracts light, depending on its normal-vectors, but particles lack any normal-vectors.’

And the answer for what to do next is, to render the particles based on deferred rendering. In other words it’s still alright if the particles are point-sprites, as long as the Fragment Shader renders a depth-map of these individual entities. That depth-map will correspond to the map, which is produced with deferred rendering, and subject to post-processing.

What needs to happen next, is that this depth-map needs to be smoothed, in a way that leaves no holes in the fluid, but which also leaves surfaces at a tangent to the virtual camera-position, where the edge of the virtual fluid is supposed to exist. This means that a special smoothing function is needed, that weights the distance of individual particles, according to a spherical function:

K = SQRT( Radius^2 – X^2 – Y^2 )

Z’ = Z – K

And then, the normal-vector can be computed from the resulting, modified depth-map. This normal-vector can be used to reflect and/or refract an environment-map, but in the case of refraction, the density of the virtual fluid must also be computed realistically, since most real fluids are not perfectly transparent. This could be done using alpha-blending.

Now, there is an extension to this approach, that uses ‘Surfels‘…

In general, Surfels are particles that follow a surface.

The way turbulent water in a river could be modeled, is as an intersection of two surfaces, one being the neutral surface of the water, and the other defining a concavity around the watery surface, beyond which water cannot flow – the riverbed.

The dynamics of individual particles can be modified such, that while a certain distance above the surface, they follow gravity downwards and are accelerated towards the surface, and while below the surface, they follow buoyancy and accelerate upwards towards the surface. Their movement in all 3 dimensions is still constrained by pressure.

Collectively, this swarm of particles will represent a fluid as before, and will need to be rendered, similarly to how the particle-fluid was rendered above.



Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>