r/howdidtheycodeit • u/VegeTiger • Mar 09 '22
How is in-game real time fluid flow simulated?
Typically, fluid flow simulation need solve complicated fluid flow equation sets, which take a whole subject called computational fluid dynamics (CFD) to deal with it. And the simulation usually takes quite a few computational powers.
However, in games, there are many real time fluid flow simulations, like water pool, sea, overflow over objects, they are simulated pretty well, although not accurate, but visually good enough. And it is amazingly fast.
I am wondering how did they model and coded this? How to simplify the problem? Thanks.
Update:
For example, Battlefield, Soldiers swim through, or boat floating and running on it, it looks good enough, considering the game need handle all those other effects.
And for example, Cities Skylines, The water flows with the terrain, and if terrain changed, the water flow changed.
21
u/BBonless Mar 09 '22
Some examples of the games you're talking about would be nice
Afaik most games use a lot of cheating basically. Normal maps to add details, Vertex displacement for waves, etc.
In 2D you can definitely pull off a good SPH (Fluid dynamics with particles) in real time.
18
u/VoidOB Mar 09 '22
hi , as someone who is working on a game based on fluid simulations for the past 7 years (back and forth) I realized after so long that somehow the answer is always a collection of as-much-as-you-can-fit type solutions what is your focus ?
do you need it just for visualizations no intensive interactions or gameplay ? then its the 2.5D flow grid
do you want it to take no performance then use voxels or cell-based solutions like FLIP
do you want gameplay mainly ? then its particle based technique like SPH
is memory or ram not a problem for you then head on to ML like how Ubisoft does with their cloth simulations , same can be applied to flow fields and meshes
do you just want to simulate ocean-like waves then wave equations are way too common
do you want it for objects instead of environment then alembic is the best
if you did not aim at one thing then shuffle between them ,a good example is SideFX houdini's FLIP , its so diverse and adaptive based on what you want , you don't have to simulate kilometers size of particles just to get an ocean wave but when you need them it will automatically be there for you seamlessly .
for your examples
-uses tessellated plane simulated with wave equations because you can see the other waves canceling each others when moving forward-backward
-(really not sure) depth texture generated from terrain + manual approach for flow(divergence) expanding based on heights since it doesn't look like it uses SDF probably faked on GPU since most texture based technique ALWAYS happen on GPU
7
u/-Zlosk- Mar 09 '22
For Cities: Skiylines, per the answer to a similar question, it's a flowmap that is updated with each physics step. Per a blog I found, it's cellular automata. These answers seem kind of the same to me, since the rules for the cellular automata would be the same rules to generate the flowmap.
5
u/Orcthanc Mar 09 '22
The 2 methods I know are:
z += sin(x + time)for an ocean in a shader. Also, a lot of waterfalls are just a moving texture.2
u/klamacz Mar 09 '22
Usually its asset prepared for given situation.
If water flow or effects don't change when you put dynamic object inside, then there is no advanced simulation there.
Only game which I know did it very precisely is SpinTires and its limited to small areas.
2
u/Drag0nV3n0m231 Mar 10 '22
Mostly, the look of the water is just an animation for any game not focusing on it, paired with some fancy gravity, games like battlefield would use this.
For games like cities, gotta see other comments
2
u/isolatrum Mar 10 '22
Fancy shaders, basically. They don't really use physics engines, it's all just math on the graphics card
2
u/DopamineServant Mar 11 '22
https://youtu.be/BqJm3B8cubo
0
u/[deleted] Mar 09 '22
[deleted] — view deleted comment