Game
The Mission: Demo
6 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

Just as Pecaminosa's musicians #improvise this rendition of #LittleSunflower 🌻, so do we improvise with this post you're reading. 😂

What's coming out of your own improvs? 🤔

#Pecaminosa | #IndieDev | #OST | #Jazz

Did you know that today is #InternationalJazzDay? 🎷😎

No? 😯 Well, we couldn't pass up this date!

And what better to celebrate this day than #Pecaminosa #OST? 🎷

Let us know what you think about it and have a great weekend!

Been working lately on lots of 'behind-the-scenes' boring stuff that no one really cares about, so here’s a guy playing the sax for some reason.

#screenshotsaturday

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…

Runestones: from concept to in-game model🗿

Protege el conocimiento, salva la historia. Guardian of Lore es un platformer 2D en el que debes luchar para mantener viva la memoria de la mitología latinoamericana. El juego llegará a Steam el 18 de mayo: https://steam.pm/app/1211740 #ScreenshotSaturday

Quantum precognition is one of the most powerful cards. End game cards & equipment. Demo/alpha build boss is no match for this deck.

The whole squad is here!

Interested? Follow me!

I-Buki

Mio-Da!

Ibuki Mioda!

The Darkside Detective: A Fumble in the Dark is out TODAY! 🖱️Advanced pointing, clicking action 🖨️Very funny words! Loads of them! 👻6 sarcastic, spectral cases to solve