Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Improving the foundation of our falling sand simulator (jason.today)
108 points by jasonjmcghee on May 17, 2022 | hide | past | favorite | 31 comments


These days when I want a falling sand game, I go to https://sandspiel.club/


Allow me to recommend The Powder Toy[0]. It is to date, as far as I can tell, The most advanced falling sand game available, aside from maybe Noita, though the focus there is quite different from most falling sand games. It has hundreds of different elements to play with. It simulates air pressure and can with the toggle of a button simulate ambient heat, water pressure, and newtonian gravity. People have built everything from bombs to CPUs in it.

Disclaimer: I did some minor development work on TPT and am involved in the community. Still though, great game.

[0] https://powdertoy.co.uk/


Absolutely! I mentioned it in my first post. Great implementation and a good blog post about how it's made.


Recent and related:

Making a falling sand simulator - https://news.ycombinator.com/item?id=31309616 - May 2022 (65 comments)


There's something about the feeling of this that reminds me of being much younger, running demos in DOS, and how insanely performant they'd be at running the same sort of thing.

It was like magic at those times.

This is so far abstracted from the magic hyperoptimizations that were used for those demos it's mindblowing, but it's still fun to see and neat to play with.


Love the gravity addition, that's a clever trick for dealing with fractional velocity. Pausing rendering when there are no changes is also a nice touch.

I notice on my machine the background is initially white and only acquires the grey background color after a sand has fallen past a given pixel. I encountered the same bug when building my own version off of this from your last post, my fix was to initialize the dirty set to be the full set of indexes for the first frame. Also, some of the buttons are pure white, the text is invisible. (I suspect both of these are light mode only bugs)


I thought treating fractional velocity as the probability to move was a fun hack. Unlike rounding, it makes it feel a bit more fluid as the batch of particles placed at a time step move two different distances.


The light mode bugs should now be fixed. Apologies for that.


Works great!


Oh no! I clearly have a bug. I develop in dark mode and apparently broke something during this post and didn't verify light mode. I will look into it now!


Very nice job. You did some massive improvements since the previous article. I will try to follow along with a GPGPU implementation. Thank you!


Thank you! I'd be very interested to see that. I've had a couple of fun Sundays now. I'm looking forward to the next pieces- but moving the logic to the gpu (either by shaders or GPGPU) has not been something I've been planning to do.


The simulation being massively parallel, it is a perfect fit for a fragment shader. Since the interactions between the particles are mostly local, taking advantage of the fact that the GPU loads a block of neighbouring fragments in the cache to be able to compute the standard derivatives, it should run very well. I will notify you when I find some time to play with it.


This is really awesome!

Anyone remember Sony-J5 Mobile? I first seen falling sand there. Jason's version is a ultra fast version (and cool!).

https://www.sony.ee/electronics/support/res/manuals/3227/322...


The acceleration was my main gripe with the previous iteration. Thanks for adding it!

I want to stay up to date on this blog. Is there an RSS feed anywhere?


I'm glad you are enjoying the posts!

I'm hosting on Github Pages, which seems to have a feed plugin for RSS, so I'll investigate that! Right now I've just been posting to Twitter (so far it's the only thing I've used it for) and HN.


Nice, I’m glad to see another post from you!

As someone else mentioned, this has intense nostalgic vibes. Something about the acceleration of the sand maybe?

You really knocked it out of the park in any case, the end result is fantastic. I’m looking forward to digging in deeper.


Fun!

Small bug: if you two finger touch on iOS (or hit clear all), the screen clears to a different color background, lighter than the new sand dispenser, so now the sky becomes darker as you drag around.


Should be fixed now! Apologies for that! Clearly needed to test light mode more thoroughly.


Nothing like some good old elegant untyped JS


Wow why is this so fun and joyful :) So satisfying...


Reminds me of the 1991 Archimedes game Cataclysm.


Can't restart it after it falls?


You can just click "Clear All". Or right click on Web / tap with two fingers on mobile.


Nice! How about a 3d version? :)


If there's interest, I can definitely take a crack at it!

My current plan was to introduce some new particle types as there is some pretty stimulating emergent behavior that comes out particles with different rules interacting with one another.

I'm also really interested in exploring 2D velocity and acceleration- how we could go about enabling particles to be thrown and bounce off of walls- or each other.


If you don't mind spoiling your plans, are you thinking of continuing with the subclass-per-particle type approach, or eventually moving to something like a simple ECS architecture?


A full ECS architecture? I don't plan on it. But using some sort of trait / component structure could be worth if enough particles with a mixture of different and overlapping behaviors were introduced.


On Safari and Chrome I get `TypeError: p.before is not a function. (In 'p.before()', 'p.before' is undefined)` from falling-improved:171

Nothing gets rendered.


This is what happens when you try to fix a bug while your post is on the front page. Yikes. Should be fixed.

You might need to force refresh.


Have you thought about modeling aeolian transport (wind-blown sand?) the mechanics of it are poorly understood and this could be a decent starting point. I know the other models attempting to capture aeolian transport are extremely lacking.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: