Liquid simulation

Hey,

I was searching on google but did not find too much info, so how would you guys go about liquid simulation using jMonkey?
Could you please give me some pointers at least where to look on this topic?

Thanks,
Adam.

JME doesn’t have any out-of-the-box fluid sim tools. However it can visualize most anything. Fluid sim is a tricky area, lots of performance tradeoffs for whatever technique you use. I haven’t researched it so I cannot go into detail further, sorry.

There are numerous imperfect approaches to fluid simulation each with its own significant limitations and/or performance trade offs.

Probably no one will be able to answer you unless you discuss in some detail what your requirements are. It could turn out to be impossible or you may have to scale your requirements back greatly. In the general case, fully accurate fluid simulation is not really possible in a game setting.

Also, “fluid simulation” is probably what you should be searching for.

Hey,

first of all thanks a lot for your inputs! :slight_smile:

Secondly, I don’t want a very serious simulation, I thought about something what the game Terraria has except in 3d. The fluid would have a volume and if you let’s say modify the terrain around it it fills in the holes but its level decreases (so somehow the volume would stay kind of constant). When the player enters the fluid it could kind of swim which is basically just modifying the gravity and some decrease in speed (moves less fast). Also when the player’s head is underwater the view would be different (like in Minecraft, the screen becomes blueish).

Just an idea what I have is that maybe it could be a simple plane (I mean the surface of the water) and it could have a special material that would give some water-ish look (also maybe particles). Detecting if the player is in water or not would be simply checking if the player character is below this surface or not. I guess some sort of post filter or something could do the trick.

The volume however is more tricky, I have a heightmap based world and I plan to introduce the player the possibility to modify the heightmap, so let’s say if the player digs under the water then the volume staying constant the water would fill in the hole and decrease in level.

Considering these requirements could you give some ideas how to solve it?

Thanks.

The water approaches you have described are voxel-based approaches and generally use a form of cellular automata to do the “flowing”. Searching for “voxel fluids” or something might yield results. I recently read an article where each voxel held a volume and a flow direction. A water level may be sufficient for your purposes.

This is quite a deep pool (heheh) to step into, really.

Voxel fluid simulation and cellular automata might be good topics to look into.

1 Like

I see two approaches, with different problems.

Approach 1: Adjust the water level instantly. If the water surface increases at the new height level, the height change will be less than one would expect by simply dividing the changed water volume by the surface area.
Finding the list of changed shorelines efficiently is going to be tricky.

Approach 2: Adjust the water level slowly over time. This will push the game world towards the more natural. However, you have a water body with gazillions of voxels, each of them has to check whether any of its neighbours has a lower water level. The mere number of calculations can quickly overwhelm any CPU.
On the plus side, if you’re doing voxel stuff, you generally use larger voxels for large uniform volumes, if only to keep the rendering times reasonable.
On the minus side, your water body might stretch across a whole planet. Or at least out of sight and affect a potentially very large number of voxels.
On the plus side again, you can do optimizations:

  • If the amount of water exchanged between two voxels falls below a given threshold, just distribute the water evenly and mark both voxels as constant if they reached a static equilibrium. (You can still have fluctuations if voxels are connected as a ring. Or even with just four adjacent voxels. Stabilizing potentially fluctuating simulations without sacrificing more accuracy than one wants is complicated.)
  • You can run the updates for out-of-sight voxels at a lower rate and exchange more water each time.

I think I’ll be going for the voxel approach once I start fluids.

Strongly related

also for everyone not knowing this site, it’s like the goldmine for gamedevelopers :slight_smile:

@Empire Phoenix said: Strongly related http://www.gamasutra.com/blogs/MatthewKlingensmith/20130811/198050/How_Water_Works_In_DwarfCorp.php also for everyone not knowing this site, it's like the goldmine for gamedevelopers :)

Haha… that’s the article I was thinking of. Thanks for finding it. :slight_smile:

Yeah, gamasutra is great.

Note: if you have ‘oceans’ then you probably want a special ‘infinite’ water level which prevents the issues toolforger talks about.

also, consider that in a lot of game they just have a “level of water” implementation, like in morrowind (i don’t know for oblivion/skyrim, but it seems to be true too from the game-point-of-view).

It’s not really relevant to perform a lot of calculation to find the level of water dynamically. And, if you go this way, you have to consider the liquid deplacement (if you have a cup with a hole, all the water will SLOWLY go out of there => very hard to code).

In most of game, the level of water is not moving, or moving “programatically”, i.e. in response to some event (like the player flush something => you decrease manually the level of water). It’s a lot easier to handle the comportement of the water in-game than to have an automatic way to do it.

About the appearance : we already have a very nice shader for this.

And think about something : we already have enough problem to get a nice syncz with the bullet engine through network. With fluid simulation, if it’s not purely cosmetic, it will become even harder, near to impossible.

Thanks everyone for the answers! Lot of interesting things to search and read!

By the way, is there a voxel terrain engine for jMonkey? I’ve found some people already working on such things and like if I remember that there was something like that but could not find now?

look into the contribution repository, if i recall correctly there was some kind of block engine in it.