processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.38k stars 3.28k forks source link

noiseMode(SIMPLEX)? #6152

Open kaitabuchi314 opened 1 year ago

kaitabuchi314 commented 1 year ago

Topic

I think Simplex Noise would be a very good enhancement. It seems p5.js is not working on it. If you want to make sure that the previous projects don't break.

A fix for this may can be done like centering rectangles, I fell that it would be a good idea to have maybe a noiseMode(SIMPLEX) and noiseMode(PERLIN), this would allow a decision by the user, if they want Perlin Noise they could use noiseMode(PERLIN), or just leave it out (It could be the default for compatibility), or if they want to use (better) Simplex Noise they could use noiseMode(SIMPLEX).

Here are some reasons Simplex is better (Thanks ChatGPT):

  1. Improved computational efficiency.
  2. Higher quality and smoother results.
  3. Improved isotropy and higher-dimensional performance.
  4. Easier implementation and understanding.
limzykenneth commented 1 year ago

Hi @thecodingcookery, I think this should count as a feature request and as such with all feature request, we require that an explanation of how this feature increases access to p5.js from different angles of diversity, you can read more about it here. I'll leave this issue open for anyone to chip in on the access statement. Thanks.

hellonearthis commented 1 year ago

Yes, this would make for a good feature, epically since the simplex patent expired on January 8, 2022

If you do submit a feature request @kaitabuchi314 you could consider these points.

The addition of simplex noise to the p5.js library from an accessibility standpoint.

limzykenneth commented 1 year ago

@hellonearthis Only very recently realised there's a patent on Simplex Noise, which was quite surprising (to me), probably also why it wasn't used in Processing and p5.js before.

I'm happy with this feature being implemented in this case. I feel noiseType() is more semantic but noiseMode() will probably be the more familiar and better option.

Tagging math stewards @jeffawang and @AdilRabbani if you wanted to review this before approving this for implementation in a PR.

Qianqianye commented 10 months ago

Thank you all for working on this issue. I am inviting the current Math stewards to this discussion @limzykenneth, @ericnlchen, @ChihYungChang, @bsubbaraman, @albertomancia, @JazerUCSB, @tedkmburu, @perminder-17, @Obi-Engine10, @jeanetteandrews. Would love to hear what y'all think. Thanks!

Vishal2002 commented 7 months ago

Is it still open to contribute ? Love to discuss the problem and work on the solution

Vishal2002 commented 7 months ago

@kaitabuchi314 Do you need a separate function named noiseMode() which takes what type of noise the user need?

Vishal2002 commented 7 months ago

@limzykenneth Sir the patent is over and I think now we are good to go with the implementation of this feature. While looking for the Simplex noise with js I found this repo [(https://github.com/josephg/noisejs)]. Hope this helps in implementation.

limzykenneth commented 7 months ago

In view of the 2.0 RFC in #6678, I think for this change we'll just directly implement it as part of 2.0 with Simplex noise being the default noise implementation and not providing the older Perlin noise (nor noiseMode). For those that need the older Perlin noise implementation, a addon style patch file can be used to patch into the older behaviour.

mattdesl commented 3 months ago

The current p5 noise function has some quirks that I think would be worth ironing out:

// global noise tied to randomSeed
const v = noise2D(x,y);

// instance noise with specific seed
const noise = Noise2D(mySeed)
const v2 = noise(x, y);

If a larger proposal is required for these changes let me know, but I feel they would be good candidates for a v2 overhaul of the noise functions.

In terms of implementation, I would recommend using an existing library, these are two modules that I like: https://github.com/jwagner/simplex-noise.js https://github.com/joshforisha/fast-simplex-noise-js (more modular, note my perf improvement here)

limzykenneth commented 3 months ago

@mattdesl All really good points, thanks! I think as you mentioned there are probably space to flesh out some of the details as a larger proposal, I think if you prefer a proof of concept implementation may be helpful tool. A couple points below:

I personally think the noise() function should be 'raw' — as far as I understand, p5 currently provides some kind of fractal/octave and level of detail when using noise, which makes it hard to use practically. This should be moved into a new function like fractalNoise2D(x, y, levelOfDetail)

For this I would actually go the other way round and have a rawNoise() function instead. This is because not having that kind of fractal behavior is a very massive breaking change, not only potentially breaking user's code but also breaking many of the tutorials out there that expects this.

The random seed should be aligned to the noise in my opinion, so that fixing the random seed also fixes the noise randomness, rather than requiring two seeds to be set. This is something I have noticed many students get tripped up about when they first start using noise.

There may be a case where a specific random stream is being relied upon in the RNG but a different noise stream is being relied upon for seeded noise so I'm not sure about aligning the seed here. Or someone may want to seed their noise but not seed their RNG to get some uncontrolled randomness that works with fixed noise.

davepagurek commented 3 months ago

It would be good to support higher dimensions like 4D noise

Just adding a +1 for this! If that's easier to add with a simplex noise implementation, then that would be great.