Heightfield fluid simulation

Show off your games, demos and other (playable) creations.
Post Reply
Jorzi
Prole
Posts: 11
Joined: Wed Mar 19, 2014 9:14 am

Heightfield fluid simulation

Post by Jorzi »

I managed to make a shader based heightmap fluid simulation that runs in shaders in LÖVE.
I added some basic shading as well as adding/removing fluid with LMB/RMB.
The algorithm is a slightly modified version of the "Pipe method" described in https://trepo.tuni.fi/handle/10024/115052
Basically it assumes that the hydrostatic pressure is a direct function of height and flow can only happen in vertical and horizontal directions to neighbor cells (therefore pixels can be mentally thought of as square basins connected with a grid of pipes). I also added a blurring step after every 3 simulation steps for stability (simulates viscosity)
fluid_example.jpg
fluid_example.jpg (350.96 KiB) Viewed 6557 times
Attachments
heightfield_fluid.love
(510.6 KiB) Downloaded 332 times
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Heightfield fluid simulation

Post by BrotSagtMist »

I mean yes, this looks great, cool light play and depth.
But i only get 1 picture every 10 seconds.
More of a sirup simulator.
obey
User avatar
dusoft
Party member
Posts: 654
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Heightfield fluid simulation

Post by dusoft »

Very nice! Good physics where there are some hills.

BrotSagtMist: don't forget to click, completely fluid here.
User avatar
marclurr
Party member
Posts: 158
Joined: Fri Apr 22, 2022 9:25 am

Re: Heightfield fluid simulation

Post by marclurr »

dusoft wrote: Wed Jul 17, 2024 10:55 pmBrotSagtMist: don't forget to click, completely fluid here.
Pun intended?

Works really nice for me too. It's quite a mesmerising effect.
Jorzi
Prole
Posts: 11
Joined: Wed Mar 19, 2014 9:14 am

Re: Heightfield fluid simulation

Post by Jorzi »

BrotSagtMist wrote: Wed Jul 17, 2024 7:16 pm I mean yes, this looks great, cool light play and depth.
But i only get 1 picture every 10 seconds.
More of a sirup simulator.
Hello BrotSagtMist, what graphics card do you have? This simulation is run 100% on the GPU. I didn't consider the performance at first, because I am using an NVidia RTX 2080, but I now made a lighter version.
I am uploading a lighter version where I reduced the fluid calculation resolution to half (heightmap remains at full resolution). I also increased the timestep as much as I could without ruining the stability, then I reduced the calculations from 24 to 4 simulation steps per game tick, so this should now run 24 times faster.
Attachments
heightfield_fluid_halfres.love
(510.6 KiB) Downloaded 302 times
User avatar
dusoft
Party member
Posts: 654
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Heightfield fluid simulation

Post by dusoft »

marclurr wrote: Thu Jul 18, 2024 6:25 am
dusoft wrote: Wed Jul 17, 2024 10:55 pmBrotSagtMist: don't forget to click, completely fluid here.
Pun intended?
Indeed.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Heightfield fluid simulation

Post by pgimeno »

The OP's version works at 5 FPS in my 10 year old desktop (nVIDIA), at 36 FPS in a mini-PC (Intel), and at 120 FPS in a gaming laptop (nVIDIA), all with vsync on. It seems very sensitive to something, not sure what; maybe the graphics driver abilities to optimize shader code.
Jorzi
Prole
Posts: 11
Joined: Wed Mar 19, 2014 9:14 am

Re: Heightfield fluid simulation

Post by Jorzi »

I wonder if the performance drop could be because I used rgba32f canvases for the fluid sim. I reduced the bit depth to 16 bit and it still seems to run just fine.
Attachments
heightfield_fluid_16bit.love
(510.59 KiB) Downloaded 331 times
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Heightfield fluid simulation

Post by pgimeno »

That helped! Now it runs at 30 FPS on the desktop, at 60 FPS on the mini (i.e. it's maxed out), and still at 120 FPS on the laptop (which is also maxed out).
Jorzi
Prole
Posts: 11
Joined: Wed Mar 19, 2014 9:14 am

Re: Heightfield fluid simulation

Post by Jorzi »

60 fps on an intel GPU sounds like good enough performance for me :), thanks for your valuable testing.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 9 guests