Live data from Hacker News

Simulating water over terrain

lisyarus.github.io

11–20 of 60 posts

Re: Simulating water over terrain

#11

Guess this explains why water effects in Minecraft are bit kludgy. It isn't so simple.

Water and lava in Minecraft were originally even simpler flood fills. If you dug into a source at max height (64) of the 256x256 map, it would flood the entire world with an expanding wall of death.

Re: Simulating water over terrain

#12
Off topic, but the post mentions needing terrain manipulation for resource gathering.

I always thought animal crossing had a clever and efficient approach to this without any terrain manipulation. You can chop a tree, and it'll dispense logs, but only so many before it essentially has a cooldown. You get the feedback and the finite resources, without expensive terrain manipulation.

Of course that doesn't work for every game, and really works better on smaller maps, but something worth considering. Terrain manipulation is pretty expensive, if your game doesn't need it it's probably better to do without (again, a generalisation)

Re: Simulating water over terrain

#13

Off topic, but the post mentions needing terrain manipulation for resource gathering. I always thought animal crossing had a clever and efficient approach to this without any terrain manipulation. You can chop a tree, and it'll dispense logs, but only so many before it essentially has a cooldown. You get the feedback and the finite resources, without expensive terrain manipulation. Of course that doesn't work for eve…

The blog mentioned that strategy, in the form of gold ore in a gold ore boulder found lying around

It a standard strategy for resource dispensation (though cooldown doesn’t alleviate the infinite resource problem; it just slows it down), it’s just… boring and unimpactful

Re: Simulating water over terrain

#14
This is super, super cool!

I was experimenting with a similar idea recently with the help of o3-mini-high. I talked it through my idea for an algorithm, and it implemented and rendered it in 3D with no manual intervention (although I did prompt it a number of times):

https://3d-water-sim.netlify.app/

It's not perfect yet because I stopped playing with it, but it was improving significantly with each iteration.

Fun fact, it implemented a working version of perlin noise correctly from scratch instead of pulling it from a CDN or something as part of this, for the terrain generation.

Re: Simulating water over terrain

#15
The waves when the water is first entering the area is called numeric dispersion, it's a consequence of discretizing. It can be mitigated somewhat by smoothing the entering wall of water so that there's not a sharp discontinuity.

Re: Simulating water over terrain

#16

The waves when the water is first entering the area is called numeric dispersion, it's a consequence of discretizing. It can be mitigated somewhat by smoothing the entering wall of water so that there's not a sharp discontinuity.

Interesting, thanks! Is it kinda like the Gibbs phenomenon?

Re: Simulating water over terrain

#17
Storing values at the edges of cells makes the math simpler, but unfortunately makes a GPU implementation harder.

In this setup one edge update affects two cells, so the cells are no longer trivially independent. It's still possible to update cells in parallel, but it requires splitting the update into two checkerboard-like passes.

Re: Simulating water over terrain

#18
post #17

Storing values at the edges of cells makes the math simpler, but unfortunately makes a GPU implementation harder. In this setup one edge update affects two cells, so the cells are no longer trivially independent. It's still possible to update cells in parallel, but it requires splitting the update into two checkerboard-like passes.

It's true that it makes it more complicated on the GPU side in general, but specifically in this scenario everything works out just fine, mostly because all updates effectively ping-pong between flow & water height buffers, and you never change both in the same kernel.

Re: Simulating water over terrain

#19

The waves when the water is first entering the area is called numeric dispersion, it's a consequence of discretizing. It can be mitigated somewhat by smoothing the entering wall of water so that there's not a sharp discontinuity.

I don't think so, the waves are actual shock waves which are a solution to the Riemann problem for the shallow water equations because they are nonlinear hyperbolic equations. You can find them even before you start introducing any numerical grid or discretization.

See e.g. the classic exposition by Leveque:

https://www.clawpack.org/riemann_book/html/Shallow_water.htm...

Post reply on HN