jwagner / simplex-noise.js

A fast simplex noise implementation in Javascript / Typescript.
MIT License
1.61k stars 130 forks source link

Analytical derivatives? #57

Open jonikorpi opened 1 year ago

jonikorpi commented 1 year ago

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:

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

jwagner commented 1 year ago

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. :)