Real-time hydraulic erosion using compute shaders - OpenGL

Published March 16, 2024
Advertisement
2 likes 10 comments

Comments

JoeJ

Wow, i see your rivers form moving meanders. Awesome! :D

Do you sue particles for the water, probably SPH?

March 16, 2024 06:26 PM
buzzelliart

@JoeJ thank you 🙂 Yes, I use particles inside a compute shader. I don't know what SPH stands for, is it a common algorithm used for particles simulation?

March 16, 2024 10:20 PM
JoeJ

Yes, it's usually the first approach people try to model water: https://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics

To interact with other particles, each particle searches for neighbors within a radius, to estimate things like pressure or velocity, or to resolve collisions. Usually that's 20 - 100 other particles, so it's quite expensive.

Traditionally there are two main approaches for erosion simulation on a height map:

The ‘droplet’ approach, using particles affected by gravity and ‘painting’ to the terrain. But the particles do not interact with each other, so it can't form lakes like you have, and they also don't form rivers. It can erode, but it's no fluid.

Or the 'shallow water' approach, not using particles but height of water per grid cell, flowing to / from adjacent cells. Games often use this to model interaction with water surfaces, e.g. walking through a puddle or waves from a boat. It's the fastest way to simulate some form of fluid, requiring neither a neighbor search nor a solve for a divergence free vector field. And it can do lakes or rivers.

I've tried all of that, for now ending up with SPH for 3D and shallow water for 2D.
But yours is the most realistic water for terrain i've ever seen. Really good! :D

March 16, 2024 11:49 PM
buzzelliart

@JoeJ very interesting, i also did a bit of research on the subject but i didn't know the exact name of the approach. I tried to get inspiration from different approaches. The result is still far from perfect but i like the effect i get till now. the erosion still does not seem very realistic since it tends to create very narrow water beds, but I have some ideas to try to improve on that side.

March 17, 2024 08:40 PM
JoeJ

Personally i use curvature to prevent pits becoming too deep, which seems to be a problem for you. If a spot is already deeper than its surrounding, i make it more resistant to further erosion. This works pretty well and curvature is generally useful to give some art direction. E.g. if a want smooth and flat areas, i make spots easier to erode which are higher than the surrounding.

March 17, 2024 10:23 PM
buzzelliart

@JoeJ very interesting approach, i usually managed the problem in my previous CPU implementation by making the erosion affect a an area within a certain radius instead of a single cell, but your approach seems a lot more rigorous, it would be very interesting to see your results, have you shared them somewhere?

March 18, 2024 03:43 PM
JoeJ

I have posted results here in random threads, usually when they went off topic.

Some example:

That's all 3D fluid simulation. Mostly MPM, just water and erosion uses SPH.
You can see the material in the valleys looks smoother than the rocks. But it's all the same technically. I have used the curvature tricks for this effect.

Some random experiments, showing more alien kind of stuff:

This can create some cool environments and patterns for sure. No need for ‘generative AI’ crap. \:D/

But it's quite experimental for now. No texturing yet, no node graph interface to manage settings, etc.

And 3D is slow. So the next step is to work on heightmap simulation too, but on the surface of meshes. I still have a long way to go, to get to reasonable close up detail… ; )

March 18, 2024 05:21 PM
buzzelliart

@JoeJ very cool! yes, a node graph interface would be cool, i want to add it too to my engine, but seems a bit difficult to implement from scratch, maybe i should look if some small library already implements it, maybe there is a small extension of imgui that implements it, i think i've seen it in the past.
Is your computation done via compute shaders or on the CPU?

March 20, 2024 10:17 AM
JoeJ

I've looked for a imGui node graph lib just recently, but found 3 of them quickly. Seems we're spoiled for choice. : )

I do do all on CPU. I have a port to GPU in mind, but GPU code is hard to maintain or change. So i'll do that only much later eventually, when i know which code is really needed and what goes to the trash bin.

March 20, 2024 05:02 PM
buzzelliart

@JoeJ yes that's a wise way of proceeding, but unfortunately not always what works well on single threaded CPU will work on the GPU side, due to conflicts among threads.

March 25, 2024 08:03 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement