Grant-Nelson / OpenSimplexNoiseDart

OpenSimplexNoise implemented in Dart
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Periodic noise #1

Closed unicomp21 closed 3 years ago

unicomp21 commented 3 years ago

Is there any way to get tiled, periodic noise? Any way to add an eval6D? Which could be used to created tiled 3D noise via sin/cos?

Grant-Nelson commented 3 years ago

Thanks for adding an issue. I am not the original designer of OpenSimplexNoise. Professor Ken Perlin invented Simplex Noise in 2001. I based my version off of Kurt Spencer's 2014 Open Simplex Noise in Java. All that to say, I'm no expert on the mathematics of Simplex Noise.

However, if you want periodic noise you could do something like pick an initial value and your period (i.e. distance before repeat). Then, based on the linear distance on the axii that you want to have period noise on, you fade out the noise from that initial value and fade in the noise with that initial value offset by the period's distance. That way at the periodic distance the noise will restart. You can either do linear/bilinear/tri/etc interpolation or trigonometric interpolation, whatever looks the smoothest for the number of axii that are to repeat. Although, since the point of this noise is to be replicable pseudo-random which doesn't repeat, I would look to see if there are some other noise algorithms designed to repeat and suited for what you want first. (For example, maybe a Perlin "Classic" noise with a finite list of random numbers which loop instead of using a normal pseudo-random number generator.)

There is a pattern that can be seen in the growth of dimensionally. When I did 2D, 3D, and 4D I tried to simplify the equation from Spencer's version to leverage this pattern to make it easier to code. For 2D there are 8 initial points and conditions, 3D has 24, and 4D has 64. If I am thinking about this correctly that growth is n x 2^n, meaning 5D is 160 and 6D is 384, 7D is 896, 8D is 2048, and so on. For eval6D, 384 is a lot of initial points and conditions. It may be possible to extract the algorithm more such that those points and conditions don't have to be manually written, but I haven't worked it out yet. Either something in runtime or maybe a code generator would able to do it, I just don't know.

Since you got my curiosity about the periodic noise, I may see if I can make a 2D image which has seamless edges by setting the period to the width of the image, essentially making a tileable square of noise. But I don't really have the time right now to implement a 5D or 6D version. Anyone who wants to may. Feel free to contribute and create PR as needed to implement any part of this request then I'll code review and get it in.

unicomp21 commented 3 years ago

Thanks for the tips @Grant-Nelson, appreciate it!