Perlin Noise (Classic2D) should output from 0 to 1?

0 favourites
  • I would look at the noise like anything below 0.25 as whatever your lowest texture is, above 0.75 as the highest.

    Then weighted would work similarly. But you create it at random times.

  • Yeah… You are talking about normalization. The general point I was making was trying to avoid normalization because it is inherently imprecise.

  • To avoid normalization, you'll probably want to simply adjust your output parameters, taking into account the distribution of results. As Newt mentioned in his first post, because of the inherent nature of Perlin noise and interpolation, values at the extremes will be extremely rare compared to values in the middle (simplex noise will be the same).

    As you can see with your own simulation, using classic noise, values above and below 75 and 25 respectively would probably appear less than once in 100 million.

    I found this on stackoverflow - stackoverflow.com/questions/11487759/perlin-noise-to-percentage - if you're looking for a certain percentage of your values to be x, this is a pretty great solution.

    If you want to get exactly 30% water (or some other specified value), you could do this.

    Generate your height-map.

    Place all the height-values into a list.

    Sort the list.

    Pick the value, that appears 30% into the list, as your water-level.

    Basically instead of <0.3 for 30% as would be with true random noise, it would be something like <0.43 (that's just a completely wild guess, don't take it at face value) 0.461. The great thing is that if you find the number the way described, you just need to check, find, and set the value once, and it will stay very consistently as 30% of your returned values will be under that value.

  • Yeah, I think I’m stuck with normalization after all because I’m working with infinite scrolling, so it’s impossible to add all values to a table.

    Again, I really appreciate the help, y’all gave some nice ideas.

  • I think that’s an artifact with how the perlin noise is calculated. It’s kind of hard to google info about it. According to the description of the algorithm on Wikipedia I can see a part of the calculation which will make the result tend more to a midrange value. If you implemented the algorithm with events you could correct that but I’m not sure if it would affect the look of the noise in an adverse way.

    From what I read, traditional perlin noise causes most values to be in the -0.7 to 0.7 range. But if you change that to the 0-1 range you get values like you’re testing.

    One thing you can do is scale the noise to be closer to the 0-1 range. Something like this:

    ((Noise(x,y)*2-1)/0.75)/2+0.5

    It converts it to the -1 to 1 range, scales it by 0.75 then converts it back to the 0 to 1 range.

    The 0.75 comes from your max value of 0.85. (0.85-0.5)*2=0.7 but I just used a slightly higher value.

    There’s also different way you can scale it. Using an exponent you can push values from the center.

    Value= Noise(x,y)*2-1

    Value= sign(value)*abs(value)^0.3

    Value= value/2+0.5

    The 0.3 is a bit arbitrary. But no matter the value you won’t get a result out of the 0 to 1 range.

    The way you calculate the min/max works too. You just don’t have to do that every time your games runs. The values you get will hover around the same thing for each noise type. So you can find those once outside your game and just use those values to normalize your game. You can then clamp that too if you have outliers.

    Clamp((Noise(x,y)-minValue)/(maxValue-minValue), 0, 1)

    You asked about simplex noise but I imagine that has the same quality as perlin. You could also do smoothed noise and get a perfect 0-1 range, it just looks more grid like.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No you don't have to add all values, just a sample, it scales. Here I put it together for you.

    dropbox.com/s/60uu0inwekr2iaf/classic2d-percentagedistribution.PNG

    The value on the left is the percentage chance you want it to show up, and the value on the right is the noise value threshold you want to use. There might be very slight inaccuracies due to the sample size (10m in this case), but if you run it multiple times the values should remain very very similar. For example, if you want something to show up 30% of the time, the noise value threshold you're looking at is around 0.461. This will deviate only very slightly the more values you add.

    I'm actually not sure if I'm off by a digit for the %s, maybe they should shift up row so 0 is actually 1 and 99 is actually 100. But hopefully you won't need precision more than a %. Due to the nature of noise it would be very hard for an end user to tell the difference between 30% and 29% or 31%. You could always run the simulation like I did and add more precision if you want, or just guess a number between the listed one and the next one.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)