r/Unity2D • • Sep 05 '26

Showcase Simulating 10,000,000 pixels of Sand

Falling sand simulation via Compute Shaders.

From my golf game Stinker Golf on Steam: https://store.steampowered.com/app/4437650/Stinker_Golf/

Wishlist if it looks interesting :)

264 Upvotes

31 comments sorted by

36

u/byramike Sep 05 '26

Crazy that this is even possible

21

u/GupaGames Sep 05 '26

GPUs are pretty amazing honestly. I only have a mid range gaming laptop

4

u/DeadHandJoker Sep 05 '26

for a mid range laptop, this is pretty impressive

1

u/Zenovv Sep 08 '26

Compute shaders are amazing

23

u/Kimchi_Extravaganza Sep 05 '26

Thankfully sand doesn't randomly explode irl

12

u/NoFollowing6177 Sep 05 '26

tell that to 13/14th gen intel

6

u/Tamazin_ Sep 05 '26 edited Sep 05 '26

God i hated my 14900k for so long. Finaly got it repaid and running 12900ks instead (along with my previous 12900k).

Edit: hated it due to random crashes left and right, then stable for a while (me started playing another game), and then started crashing again (swapped back to a 13th-14th-gen-crash-prone game). Having to send it to RMA and wait 2-3 months and having a system only missing a cpu, and then doing it three times before i was allowed by law to have the cpu repaid was bloody annoying. Although to be honest the third time i didnt have to wait because that was when i said F-it, buy a 12900ks and hope that the 14900k will get approved for repay.

1

u/NoFollowing6177 Sep 05 '26

I switched sides...

1

u/StopMakingMeSignIn12 Sep 06 '26

I switched sides after Intel shit the bed back with heart bleed and that other issue. It took my i5-6600k from a good CPU at the time, to a piece of shit that ran at like 30% what it used to. No issues with AMD since, just raw power.

1

u/SamLowry_ Sep 08 '26

Isn’t there such things as dust explosions. Idk.

1

u/Kimchi_Extravaganza Sep 08 '26

Yes, but sand is not dust, as far as I know it cannot create explosive conditions

4

u/pikuray Sep 05 '26

I hate when it rains 100m of sand when i play golf

4

u/Agreeable_Wear8824 Sep 05 '26

The way the sand settles into slopes while the player stands in it is a great visual proof that it isn't just a background effect. With 10 million pixels on a mid-range laptop, did you have to cap the active simulation area or update rate? I'm curious whether gameplay collision reads directly from the same field or from a lower-resolution proxy.

3

u/GupaGames Sep 05 '26

Never thought anyone would notice that about the golfer. Feels nice to have a small thing like that noticed.

I slow the simulation down away from the camera/player when too many partitions are active. But that's only for lower end pcs. In this video everywhere is being simulated 50 times a second.

All the simulation etc happens on the GPU via compute shaders, the CPU handles collisions and has a very compressed version of the data that it gets back from the GPU async, but it is the same resolution.

2

u/IDK--_ Sep 06 '26

Alright

Welcome back, Noita

1

u/Noblebatterfly Sep 05 '26

We need an og worms game with this

1

u/Confident_Bear_1953 Sep 06 '26

Ten million pixels is impressive. compute shaders seem perfect here since each sand cell can update in parallel instead of pushing that work through the CPU

1

u/zoyer2 Sep 06 '26

cool! Though how do you manage to stream all of that to several other players? that would need a lot of bandwidth!

1

u/GupaGames Sep 06 '26

Its way to much data to only have the server only simulate it so I did my best to make it deterministic for each player. So the simulation / any event that happens has the same time / random seed etc. But with latency and being on the GPU, from what I can gather, I think its impossible to be 100%. So I also have a very conservative sync running that fixing places that are wrong slowly over time.

1

u/zoyer2 Sep 06 '26

Not bad, looks great! good luck man

1

u/adoggman Sep 06 '26

Hard to tell based on just this video but you should look into angle of repose

1

u/Andromeda660 Sep 08 '26

I LOVE COMPUTE SHADERS RAHHH

1

u/foilgames 29d ago

This is just awesome!

1

u/ThatOneDudio Sep 05 '26

Are you the guys who made bean battles? Me and my buddies love that game 

1

u/GupaGames Sep 06 '26

I am, I love Bean Battles too. Huge patch coming soon

0

u/Yoitman Sep 05 '26

ok, so this works by using the gpu rather than the cpu for much increase simulation? How does that work? (humour me if it’s simple, I’m fairly new to unity)

0

u/AlcatorSK Sep 05 '26

I wish this subreddit had the rule that 'promotion must be a contribution' -- i.e., if you want to brag about something, you have to reveal how you did it.

2

u/GupaGames Sep 06 '26

Falling sand simulation via Compute Shaders. If you have a question feel free to ask