Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perlin Noise Incorrect Adjustments #96

Closed
Wolvereness opened this issue Nov 19, 2015 · 4 comments
Closed

Perlin Noise Incorrect Adjustments #96

Wolvereness opened this issue Nov 19, 2015 · 4 comments

Comments

@Wolvereness
Copy link

So, this a two part issue (but the second part is just an awareness issue).

I ported the perlin2 code to Java, using 64-bit floating point (doubles), and did plots of the raw output. I noticed three interesting aspects of the data (third aspect is second part of the issue).

  • It peaks at a non-zero number.
  • The minimum and maximum value are consistently not at -1, 1 (there are specific numbers that keep coming up, but I don't have my older, large data set).

My observations are best explained by a few histograms:
http://imgur.com/a/Izngg (note, last image is random gaussian values as a reference for histogram behavior)

The line of issue: https://github.com/bjz/noise-rs/blob/d46df3fd9e37000a45fa76aad3fcdb85f4967318/src/perlin.rs#L43

The two constants there should be removed; the data's expected value (peak) at 0 without adding a constant, and the limits are at -1 and 1 without multiplying. After removing these two operations, the data begins to behave as expected. I tested with a data set of 613416960 (0xC00 width * 0xC00 height * 0x40 seeds), and my range was (-0.9999978883709002, 0.9999978883709002). I can provide some of the resulting histograms, but I'd just like to know that they're needed before I upload them.

Third thing I noticed, the data has mysterious small-scale biases (where there is a dramatically higher incidence of values on the other side of a threshold). They're noticeable as cliffs in the images. I don't have any suggestion for addressing it, or insight to how expected they are. I just thought that it should be noted by a maintainer as a possible issue.

I'm opening this as an issue instead of a PR because I suspect that perlin3 and perlin4 should receive similar analysis. If I have time, I can attempt to analyse those as well (or make my code available for another's use).

@Wolvereness
Copy link
Author

Sniping an old chat log, I found some of the ranges for the current function (this was picked out from thousands of data sets with size 0xC00 * 0xC00).

(each row is a noted min/max selection)

Noted Minimums Noted Maximums
-0.800675447641227 1.1123296175616617
-0.723874528218387 1.1123296175616617
-0.8006825071300255 1.1123296175616617
-0.7877138412194253 1.1123296175616617
-0.7504776372780522 1.1123296175616617
-0.8006771041436008 1.1123296175616617
-0.7876648122336306 1.1123290929337615
-0.8894792771682508 1.1123290929337615
-0.822346031420712 1.1123290929337613
-0.7877175887351778 1.1123290929337613
-0.7706959041732315 1.1123285683062518
-0.8223441771297749 1.1123285683062518
-0.8223499016819922 1.1123284029264726
-0.8223525142195302 1.1123284029264726
-0.7102352606682077 1.1123284029264726
-0.8894891846471372 1.1123284029264724
-0.8894850472468953 1.1123284029264724
-0.787714454158943 1.1123284029264724
-0.8223497750159214 1.1123278782994774
-0.7301423855452309 1.112327878299477
-0.8006784094746572 1.112327878299477
-0.9999890996340166 1.112327878299477
-0.787713964770984 1.112327878299477
-0.8223460900941824 1.112327878299477
-0.8223467004746732 1.1123271882933783
-0.7392834536477099 1.112327188293378
-0.8223491813810843 1.1123219113259122
-0.8223460777733148 1.1123213867037538
-0.7877158008031947 1.1123213867037538
-0.8223458608677089 1.1123213867037536
-0.8223525630651437 1.1123206967040167
-0.770694419269677 1.1123206967040167
-0.7467912669045497 1.112320172082763
-0.8223416525820884 1.112320172082763
-0.8006770042060218 1.112320172082763
-0.7467894684160372 1.112320172082763
-0.7467894145112455 1.112320172082763
-0.7467853602044092 1.112320172082763
-0.7359526879922568 1.1123196474619002
-0.7877199760969699 1.1123196474619002
-0.7124246734388245 1.1123196474619002
-0.7877109740499973 1.1123196474619002
-0.8223455409922893 1.1123196474619
-0.9999968058564724 1.1123189574638679
-0.8894782635238295 1.1123189574638677
-0.7124318373333272 1.1123189574638674
-0.8894867465016256 1.1123142051745059
-0.7214757466188034 1.1123142051745059
-0.7214706671651869 1.1123142051745059
-0.7126018177375665 1.1123124659503922
-0.7667894915249349 1.1123124659503922
-0.7667870723097139 1.1123124659503922
-0.7877200114323987 1.112310726730575
-0.7301470718779668 1.1123107267305747
--- ---
-0.9999903142559122 0.934681372085921
-0.9999903142559122 0.9000496566999431
-0.9999903142559122 0.801992610736299
-0.9999903142559122 0.9346784243633796
-0.9999955912233782 1.001819802054225
-0.9999955912233783 0.9130040226981316
-0.9999955912233783 0.9346756640728664
-0.999996281229477 0.934679176697245
-0.999996281229477 0.879108648825073
-0.999996281229477 0.8999952095615468
-0.999996281229477 0.8628078585563326
-0.999996281229477 0.9000422278740731
-0.9999962812294771 0.9000459116308969
-0.9999962812294771 0.9130087012136008
-0.9999962812294771 0.8628096647506374
-0.9999968058564724 0.9346743641015945
-0.9999968058564724 1.1123189574638679
-0.9999968058564724 0.9000473978731948
-0.9999968058564724 0.8791204220095495
-0.9999968058564724 1.0018166443168952
-0.9999968058564725 1.0018173055232558
-0.9999969712362519 0.900000479601929
-0.9999969712362519 1.001811648862077
-0.9999974958637613 0.8999952095615468
-0.9999974958637614 0.8047282621235745
-0.9999974958637614 0.8225658782638929
-0.9999974958637614 1.0018098605938297
-0.9999974958637614 0.883026989722521
-0.9999980204916618 1.0018162127582664

So, (as per my calculator):

-0.9999980204916618 / 1.056165 - 0.053179 = -0.99999888182875005325872377895499
1.1123296175616617 / 1.056165 - 0.053179 = 0.99999888182874995857654817192389

@brendanzab
Copy link
Collaborator

Wow, well that is interesting. Must be something wrong with our implementation. :(

@Wolvereness
Copy link
Author

Must be something wrong with our implementation.

I did note what was currently (and obviously wrong): just that it's correcting (centering / scaling) data when it really doesn't need any correction.

For the other part (strange cliffs), note that this is not comparative to original perlin noise (which may actually be worse), and the improved version (found here) has dramatic performance increase without much visual impact (and statistical comparison hasn't been made yet). @amaranth has insight to that on his blog post https://www.probablycoding.com/post/optimizing-perlin-noise/.

@Razaekel
Copy link
Owner

Razaekel commented Mar 2, 2017

Closing since it looks like this issue was dealt with by @amaranth in #98.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants