Game
The Mission: Demo
5 years ago

Liquids optimizations


So, I finally have some spare time to write about what's going on with the game. Well, actually, this post is a little outdated, since I've already implemented all that stuff about a month ago, but anyway, I think it's worth describing.

So my previous post was about liquids and the challenges they pose, this post is about solutions. I started my liquids implementation by using LiquidFun, which is a Box2D extension made by Google. It was a nice start, but it had its own problems, like it could handle thousands of particles, but I needed hundreds of thousands. It also had some particle stability issues, like when the particles are inside simple (e.g. rectangular) volume everything is fine, but if you want to use some smart-ass volume like worm-pipe you're in trouble because particle pressure will almost never even out and liquid will be extremely jittery.

After some experimentation and though I came up with a solution where I modify the engine to freeze inner particles of a liquid, so that no calculations are made for them at all:

Here blue particles are frozen ones, red particles are border particles, i.e. they don't move, but take part in inter-particle collisions. White particles are the only active ones. The trick here is that there's an "activity radius" for white particles, so that for example when there're more than 3 active particles in a row all the rest get frozen toward the "center" of the liquid cluster. And on the other hand, when this white layer starts getting thinner it automatically activates particles from inside the liquid.

Further more, I'm also freezing particles that are in contact with static bodies, thus, this makes open water surface the only thing that's active. Those optimizations allow me to have ~50.000 particles without worrying much about performance on an average machine:

And that's not even multi-threaded yet, it still runs inside game loop. Making it multi-threaded and applying one more optimization (which is pretty hard to implement, but it's possible, I'm not going to go into details on this one here) will allow me to have >100.000 particles easily, but at this point there's no need in that, 50.000 turned out to be more than enough. Another positive side effect of particle freezing is that the liquid can now occupy really complex volumes like worm-pipes without any jitters. The thing is that since the inner particles are frozen there's no impulse propagation throughout an entire volume, so things even-out really fast.



0 comments

Loading...

Next up

Sometimes the suction cup get sticky. Small animation I made in Blender after doing my tutorial on picking up/dropping objects in animations. Crate model by jQueary (https://sketchfab.com/3d-models/game-ready-sci-fi-crate-d98deca6…).

Finished work on the emotions of a new character for the tank universe

One of the most critical update for Sunblaze demo. Now you are able to pet a cat! Finally!

Horror WIP A track that will be featured in a future horror game soundtrack! Stay tuned!

Likes appreciated ✌️

#gamedev #composer #horrorgame #indiegame #IndieGameDev #soundtrack

Call it 'wrong turn'!🚫 The feeling of running into a house with only one exit🚪, and being doomed to die. #pixelart #pixelartist #pixelartwork #art #pixel #indiegame #IndieGameDev #indieartist

"Day to Day" (also check spud out here he's a great guy and writer: https://soundcloud.com/spudward)

Cash Banooca

it happens

Our menu, gathered a huge feedback and positive comments among foreign audience, what you say? Game Steam: https://store.steampowered.com/app/1543090/LiBER/

A 1h30 painting, coffee break.

My twitter: https://twitter.com/loupil100