Fluid Dynamics Realitime Simulation

Hi Guys,

I’ve just found this video:

.

This looks like a realtime fluid simulation in a (approx) 4m x 4m squared room. The closest I can get used ObiFluid or Fluvio is maybe a square foot. I’ve looked at all the water assets, the closest being Megafiers believe it or not (

). Does anyone have any idea how this was produced so easily in UE4? I mean I was thinking of creating a fluid simulation in Blender and using Python to extract data, but even then it won’t be real time, and could come across a stack of problems.

Thoughts guys? Thanks!

1 Like

I don’t normally recommend assets but if Unity doesn’t have this by default there are very often assets out there available for purchase that do a similar sort of thing, this is a really advanced piece of kit so most people will charge for it anyway. I’m not sure if they’ll be this detailed though but I’m sure other people will point out what’s going on if there’s options in Unity available.

I haven’t looked at this sort of thing a huge amount but it does look nice, for Untiy by itself, the closest thing I can think of with my knowledge are World Particles, you can make some convincing looking rain with just the world particles if you take a look at how those work. I looked at various youtube tutorials and found out how to do things like electricity sparks and it worked great, blood dripping as well.

The only downside to world particles is I don’t think they are as interactive as the Unreal engine demo shown here, someone will correct me if I’m wrong though I’m sure.

2 Likes

Thanks for the suggestion, but I really need the fluid dynamics to be full bodies of liquids. Think like a whole water tanker bursting open and a realstic amount of water pouring out. I need to realtime way to simulate that effect. It looks like UE4 is doing it, and I’ve spent hours and hours trying out (and purchasing) the systems on the Asset Store. So like ObiFluid, Fluvio, I’ve even checked out a load of C++ git repos which contain the base fluid dynamics algorithms that I can maybe import, but none really stand the tide (get it?) compared to the video I’m seeing, which it’s not even struggling slightly with the fluid simulation. I mean take a look at this side by side comparison and you’ll see the amounts these simulations are costing:
https://vimeo.com/221217941
. Does anyone know where I can go to replicate this within Unity?

It could well be that Unity is limited in that area, but you’ll need to wait to see if more experienced people know about that because there might be a solution who knows? If you’re really keen on fluid physics and Unreal is the best option there’s no rule that states you can’t use a different game engine for your idea if that one works best and then work on a different game with another one as long as you know how to use them both properly.

The thing to remember when it comes to stuff like fluid physics and other simulations, this is cutting edge stuff so naturally it won’t all be feature complete and so on. So for example another big large scale thing being done these days is mesh deformation and developers are obsessed with making giant procedural planets. Examples of these two would be the snow in tomb raider which is mesh deformation and Star Citizen and their recent 3.0 update where they’ve got an entire planet rendered that you can explore and actually fly into the atmosphere of from space.

1 Like

Yeah to be honest I was considering a C++ fluid simulations plugin and using that to create procedural mesh generation of several layers of density, and then some custom shaders.

Really interesting to play around with Unity and Nvidia Flex.

Hi there,

The first part of the OP’s video shows Cataclysm, a GPU-based FLIP simulator by Nvidia. If I’m not mistaken it is still in experimental state, and the only known integration is with Unreal.

FLIP stands for Fluid-Implicit Particle. It’s a hybrid grid-particle based method for fluid simulation, the same used in many movie VFX. Fluid equations (basically pressure projection) are solved in a grid-like structure, then velocities are transferred to particles to simulate dynamics, then interpolated back to the grid to solve pressure, and so on. You won’t get even close with purely particle-based simulators (Obi, which runs in the CPU, or Fluvio) or pure grid-based methods like Cocuy. Surface/shallow water simulators are of course not even in the same league as they can’t simulate the entire volume of fluid.

Thing is, afaik Cataclysm is the only existing realtime fluid simulator of its class, and even then it is only experimental. Does not offer two-way coupling with rigidbodies, since it can only collide against distance fields. So all you can do with it for now is what it’s shown in the first video: get it to collide with a group of static objects.

So unless you are willing to work with bleeding edge, experimental stuff, or write your own FLIP solver in GPU (fun! I’d give it a try if you have the time), I’d say find another way to accomplish your goal.

2 Likes

That’s nice! However, purely particle-based methods like PBF (position-based fluids) scale far worse than hybrid ones. Small/mid scale simulations can be handled just fine though.

Once you get past a few thousand particles (like in the OP’s video), throwing grids into the mix (FLIP/MPM) becomes a necessity.

Specialized algorithms must be used depending on the situation. Up to this day, there’s no one-fits-all solution to realtime fluid simulation. The closest one to being the holy grail is MPM, but it’s kinda like the raytracing of physics: really elegant -extremely costly- solution that covers pretty much all cases (including inviscid, incompressible, low-dissipation fluids).

1 Like

Is this real-time?
https://www.youtube.com/watch?v=i4KWiq3guRU

1 Like

None of that is realtime. These take minutes or hours to simulate.

1 Like

Not usabe-in-game realtime, but no: the algorithm discussed in that specific video runs completely on the GPU and handles a couple frames per second - to a couple seconds per frame. An overview of the different scenes, their complexity and the time required is given at around 5:20. Of course, depending on the length and complexity of the scene it may still take minutes, or even hours. But it is a several factor speedup.

1 Like

I meant minutes/hours for the entire simulation, not per frame ofc.

However, I wouldn’t call seconds per frame “realtime”. That’s an order or magnitude slower than realtime, its “interactive” at best. According to the data shown in the video the fastest scene runs at 3 fps, the slowest at 0.2 fps, and that’s on the GPU. The speedups reported are vs the CPU implementation as far as I know.

1 Like

Thanks. Now I am curious how did games like Assassin’s Creed Black Flag till Odyssey manage to achieve amazing sea-like massive waves with vorticity and so on, which look very realtime. But it seems they’ve made some trick to make prebaked meshes or some shading techniques to make it look like interactive and realtime. Any ideas?

I haven’t played Black Flag a lot, but from I can recall it’s probably more like surface deformation than actual fluid simulation. I can’t find papers on it, but there’s a SIGGRAPH 2018 talk/paper on the water in Sea of Thieves that may be helpful.

1 Like

I’d bet they’re using Tessendorf-like wave simulation:
https://www.keithlantz.net/2011/10/ocean-simulation-part-one-using-the-discrete-fourier-transform/
https://github.com/zogi/ocean_demo
https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-odean-waves

This is basically surface displacement as Boz0r said, not actual fluid simulation. It also reduces the problem from 3D to 2D, since you’re only interested in the surface instead of the entire body of water, making it much simpler and faster to solve. This comes with many limitations though.

Edit: sure enough, they use discrete fourier transform (Tessendorf):
https://www.fxguide.com/fxfeatured/assassins-creed-iii-the-tech-behind-or-beneath-the-action/

1 Like

Imagine if we could get this in Unity? Maybe someday…

1 Like

https://discussions.unity.com/t/863446
If you want to follow the development and maybe suggest thing you would like to see.

Those are completely different topics and usecases tho. The link provided attempts to make good looking water in the HDRP. There is waves and shader effects, there will be foam and whatnot. However, it will effectively be a visually pleasing plane. If you remove the boarders, you have a floating plane of water.
The goal here is to have something like the water from Sea of Thieves, for example. It will be comparably fast, and all you need for most projects.

The one implemented in UE4 is an actual fluid dynamics simulation. And a quite impressive one at that. It too comes with visual effects (foam, wet stones, dynamic water colors, …), can interact with physics simulated objects, and most importantly… runs in real time. I honestly have little clue how they made it that well, but it will likely still eat up a major portion of the computers’ ressources.
It goes into the direction of an actual water / physics simulation. Something most games will not need, but nontheless insanely impressive.

I know, that’s why I suggested to suggest the expectations. Because if the half dozen existing solutions on the Asset Store aren’t enough, from Obi Fluids to the latest Zibra, then it needs to be asked properly where Unity staff actually can see it. Even if the person reads it probably won’t be the one who implements it.

1 Like