Realtime 2D Gravity Simulation
Brendan Galea Brendan Galea
25.5K subscribers
405,644 views
0

 Published On Sep 1, 2021

This has been a fun side project I've wanted to work on for a while. I had originally just planned on doing a GPU based particle fluid, but I got sidetracked by the nice looking results of the gravity simulation.

(Sorry about all the compression artifacts, kind of impossible to avoid when uploading something like this to youtube)

It is still very much a work in progress. This uses a grid based approach to simulating gravity for extremly high particle counts. All calculations are performed exclusively on the GPU. Multiple levels of detail are used (I settled on 4), to get fairly accurate approximations for nearby particles, and rough approximations for distant particles.

There are quite a few known issues. Most notable would be a pretty significant dampening effect, since intra-pixel particle forces are very underestimated. Additionally, sometimes large collections of particles moving in unison seem to hit invisible walls. I suspect this might have to do with down-sampling always using accumulating the same pixels.

I wasn't following any particular resource for this. One of the more experimental aspects of my implementation was to apply a horizontal + vertical blur to the accumulated mass fields to "spread" out the mass information so that grid cells only need to sample their local gradient, rather than sampling every other grid cell within the 11 by 11 kernel radius. I definitely need to do a bit more research on this to see if this is a method that anyone else is using, as well as to measure the approximation error this causes. Perhaps by choosing better kernel weights the error may be possible to minimize.

------------------------------ MUSIC ------------------------------
Midsommar by Scott Buckley   / scottbuckley  
Celestial by Scott Buckley   / scottbuckley  
Luminance by Scott Buckley   / scottbuckley  
Creative Commons — Attribution 3.0 Unported — CC BY 3.0

Track: Adventures — CRASTEL [Audio Library Release]
Music provided by Audio Library Plus
Watch:    • Adventures  — CRASTEL | Free Backgrou...  
Free Download / Stream: https://alplus.io/adventures

show more

Share/Embed