simplex-noise.js icon indicating copy to clipboard operation
simplex-noise.js copied to clipboard

Analytical derivatives?

Open jonikorpi opened this issue 2 years ago • 1 comments
trafficstars

Any chance you might add an (optional) way to get analytical derivatives for the noise result?

Derivatives are handy because they tell you the ”slope” of the noise, which is incredibly useful for use cases like terrain generation. It’s possible to manually calculate them by sampling the noise 3+ times, but (as I understand it) analytical derivatives are much cheaper to compute.

As a reference, I’ve found these implementations:

  • https://iquilezles.org/articles/gradientnoise/
  • https://github.com/BrianSharpe/Wombat (the _Deriv variants)
  • https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/perlin-noise-part-2/perlin-noise-computing-derivatives.html

I’ve explored adding them myself and making a PR, but honestly I’m a bit out of my depth here. :)

jonikorpi avatar Dec 12 '22 09:12 jonikorpi

Hi Joni,

Thanks for the suggestion.

I'd love to have analytical derrivatives in. With simplex-noise now being tree-shakeable there shouldn't be a size penalty and they can definitely be useful.

As far as I know they have been used in my favorite demo https://www.youtube.com/watch?v=jB0vBmiTr6o :) https://blog.datalets.ch/workshops/2016/scoda_016/iquilezles-function2009.pdf

I don't have time to familiarize myself with the code enough (again) but I'm happy to add it as a todo. If anyone else wants to give it a shot I'd be happy to review and merge it. :)

jwagner avatar Dec 14 '22 20:12 jwagner