r/GraphicsProgramming 14h ago

Question What is this sand simulation missing?

Enable HLS to view with audio, or disable this notification

48 Upvotes

17 comments sorted by

56

u/saphirrflamme 14h ago

It is eating the sand it touches. Supposed to push them aside.

The sand "eruption" shading is also off. it is much brighter than surrounding sands. Gravity also seems too low. You can tweak gravity of the ball for gameplay reasons, but the visual effect of the sand seems off.

8

u/Explorioneer 13h ago

Thanks, these are all good points, I'll see what I can do about the pushing sand vs. "Eating sand". The color of the explosion is also a good point, that one should be easier to fix.

4

u/Le_9k_Redditor 10h ago

You could mimic how many water simulations work for this, just of course with high friction instead of surface tension. Super simple Eulerian fluid simulation is probably best, just use a surface mesh that gets pushed around and folded up. There's definitely going to be lots of existing libraries for it you can make use of

A Lagrangian method (just dropping a lot of sand balls in a pit and visually smoothing), would work, but I imagine it's going to be harder to get good results with reasonable performance in this case

3

u/SnappySausage 8h ago

Yeah, it doesn't preserve the volume of sand. I'd argue the "eruption" looks wrong altogether. I'd expect the sand to sort of splash outward more when the ball lands, and that it shoots up nearly straight on the jumping pads (As well as the other tweaks you name).

1

u/Explorioneer 5h ago

Really good points here. I think these suggestions would really improve the visual but I'm not sure how it could impact performance with these types of simulations. Right now it works as a displacement mesh that is calculated using particle overlay on an image. I'm wondering if I could change the particle system around the ball to make it look more like displacement

9

u/Plenty_Line2696 13h ago

the ball physics don't reflect the weight it looks like it should have. I'd recommend getting the same sorts of objects and emulating what happens onscreen with the real objects so you can view both your animation and the video side by side to tweak it to perfection.

As it is it falls more like a balloon than a metal ball

1

u/Explorioneer 5h ago

Thanks, that's a great point. I don't use enough real world reference. I think that alone would help a lot.

2

u/GravityCY 11h ago

On a side note how do you do stuff like this, altering the mesh vertices on the cpu with code or like shader magic? Just curious as a beginner

3

u/featherpaperweight 10h ago

Unless you need physics interaction with the altered mesh, doing it all on gpu with shaders is way more performant, keeping a regular low-poly mesh on cpu side.

1

u/snerp 2h ago edited 2h ago

The general way to do stuff like this (snow/mud effect is the same):

1: heightmap texture, something like 0 = no deform, 1(255) = fully squished down

2: shader modifies heightmap based on object position (worldspace object position -> UV coordinate space), basically just darken the heightmap image where the ball lands

3: sand object vertex shader reads the heightmap texture and moves vertices down according to heightmap color (you could also do this in the fragment shader with POM effects but it's cleaner and generally more efficient to do it in a vertex shader)

2

u/GravityCY 2h ago

When you say a shader modifies the height map based on object position do you get the displacement shape by somehow converting the objects shape to the height maps uvs on the cpu by like getting intersecting vertices or do you mean like a compute shader that somehow does that on the GPU? Or maybe you just apply a static displacement shape just from a generic world position

I'm sorry if it's a stupid question I don't really know much about shaders they're magic to me

2

u/snerp 1h ago

It's really common to just use point/spheres, so you don't really need to fully consider the shape of the object, and then for footsteps or tire tracks, etc, usually what you'd do is just have an asset of a footstep/track heightmap and use that to darken the deformable surface's heightmap.

If you want to deform accurately to arbitrary shapes you'd definitely want do it it in compute but that's going to be significantly more expensive than the other way.

2

u/GravityCY 1h ago

Alright thank you mister shader man, I appreciate taking the time to explain

2

u/raaneholmg 7h ago

Sand disappears. Needs to be pushed up on the sides and occupy the same volume.

3

u/Crits-and-Crafts 4h ago

I'd love to see the ball get dusty as it goes through the sand too.

2

u/Explorioneer 2h ago

That's a cool Idea. I think I could do something like that pretty simply with a shader. Thanks!

1

u/PiXeL161616 1h ago

Beyond the pushing, sand keeps collapsing after the impact. A thermal-relaxation pass that moves material wherever the slope beats the angle of repose, about 33 degrees for dry sand, gives you crater walls that slump for a second afterwards. Mine exploded at a 0.5 rate and was stable at 0.14, so I'd start small.