swarm-game / swarm

Resource gathering + programming game
Other
835 stars 52 forks source link

Analytical gradients of perlin noise #1608

Open kostmo opened 11 months ago

kostmo commented 11 months ago

It would be nice if in the world DSL we had access to the derivative of the noise function. This would allow one to distinguish between, say, the eastern shore (to place beaches) and western shore (to place trees) of a Perlin-generated lake.

It is apparently possible to compute the analytical derivative of Perlin noise, which obviates the need to use samples of neighboring coordinates.

See:

  1. https://stackoverflow.com/questions/4297024/3d-perlin-noise-analytical-derivative
  2. https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/perlin-noise-part-2/perlin-noise-computing-derivatives.html
  3. https://catlikecoding.com/unity/tutorials/pseudorandom-surfaces/perlin-derivatives/#:~:text=For%201D%20Perlin%20noise%20we,)%20t%20%E2%80%B2%20(%20x%20)%20.

Perhaps this would entail extending the hsnoise package with a new typeclass NoiseDerivative a (c.f. Noise a) of which Perlin would be an instance.

Since the ~derivative~ gradient is vector-valued, until/unless the DSL gains support for vector values, perhaps it could be exposed as a direction without a magnitude mapped to [0, 1] representing 0 to 360 degrees.

byorgey commented 11 months ago

This sounds cool!

I guess I don't quite understand what you mean about the derivative being vector-valued. Are you thinking of the gradient ?

kostmo commented 11 months ago

Are you thinking of the gradient ?

Indeed, imprecise terminology on my part.