Reputeless / PerlinNoise

Header-only Perlin noise library for modern C++ (C++17/C++20)
MIT License
673 stars 77 forks source link

Some times I only get 0's from noise2D when I initialize with std::random_device #4

Closed JohanAR closed 2 years ago

JohanAR commented 4 years ago

Simplified version of the test program I wrote:

  siv::PerlinNoise perlin(std::random_device{});

  for (int y = 0 ; y < height ; ++y)
  {
    for (int x = 0 ; x < width ; ++x)
    {
      const double X = static_cast<double>(x) / width;
      const double Y = static_cast<double>(y) / height;
      std::cout << perlin.noise2D(X,Y) << " ";
    }
  }

Most of the times I run the program I get values like I expect, but about 10% of the runs I only get 0, or the occasional -0, as output.

I haven't tried to track down why this is happening, but is this something that is expected from the perlin noise algorithm for certain seeds or something?

Ubuntu 19.10 Linux 5.3.0-51-generic #44-Ubuntu SMP Wed Apr 22 21:09:44 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux g++ (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008

Reputeless commented 4 years ago

I found contiguous zeros can appear when one of the noise2D parameters is zero, but I could not confirm all the outputs are zero.

I think my implementation here leads poor entropy. https://github.com/Reputeless/PerlinNoise/blob/9de88a9a6f45938485b3301480f15b565e7d040b/PerlinNoise.hpp#L164-L167


You can improve the output quality by using noise3D with an additional non-zero parameter.

perlin.noise3D(X, Y, 0.12345);

I will investigate further and make a change in the future release. Thank you for your feedback.

JohanAR commented 4 years ago

It's possible that I'm confusing two different problems I had. When I just got started I used the integer x and y image coordinates as parameters to the noise function, which gave me an empty image. To reduce the debug output I only printed the value when x == 0, so later on when I changed the code to use fraction coordinates I only saw the output from the first column.

I will try with you suggestion. Thanks for the reply!

Reputeless commented 2 years ago

resolved in v3.0.0.