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)
Heightfield fluid simulation
Heightfield fluid simulation
- Attachments
-
- heightfield_fluid.love
- (510.6 KiB) Downloaded 331 times
- BrotSagtMist
- Party member
- Posts: 659
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Heightfield fluid simulation
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.
But i only get 1 picture every 10 seconds.
More of a sirup simulator.
obey
Re: Heightfield fluid simulation
Very nice! Good physics where there are some hills.
BrotSagtMist: don't forget to click, completely fluid here.
BrotSagtMist: don't forget to click, completely fluid here.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Heightfield fluid simulation
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.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.
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 301 times
Re: Heightfield fluid simulation
Indeed.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Heightfield fluid simulation
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.
Re: Heightfield fluid simulation
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 330 times
Re: Heightfield fluid simulation
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).
Re: Heightfield fluid simulation
60 fps on an intel GPU sounds like good enough performance for me , thanks for your valuable testing.
Who is online
Users browsing this forum: Google [Bot] and 3 guests