Page 1 of 1

Perlin noise exceeds -1/1 range

PostPosted: Wed May 11, 2016 20:26
by burli
As far as I understand perlin noise the values should not exceed -1 or 1, but they do.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local testparam = {
   offset = 0,
   scale = 1,
   spread = {x=80, y=80, z=80},
   seed = 1337,
   octaves = 6,
   persist = 0.6
}
perlin_map = minetest.get_perlin_map(testparam, map_lengths_xyz):get2dMap_flat(minp)

            pi = perlin_map[perlin_index]
             if pi < -1 or pi > 1 then
                minetest.chat_send_player("singleplayer", pi)
             end


This is a snipped of the code I use (based on the example from PerlinNoiseMap, which has also a bug) and I get a lot of values below -1 or above 1, lots of them more than +/-1.5.

As you can see on the screenshot lots of the numbers are equal and it looks like they have a pattern. Is this a bug?

Image

Re: Perlin noise exceeds -1/1 range

PostPosted: Thu May 12, 2016 01:43
by duane
burli wrote:As far as I understand perlin noise the values should not exceed -1 or 1, but they do.


Quoth the master (required reading on perlin noise):

https://forum.minetest.net/viewtopic.php?f=47&t=13278#p194281

Re: Perlin noise exceeds -1/1 range

PostPosted: Thu May 12, 2016 05:48
by burli
Thanks, this should really be copied to the wiki

Re: Perlin noise exceeds -1/1 range

PostPosted: Fri May 13, 2016 03:06
by paramat
So it's possible to calculate the maximum range of a noise from octaves and persistence, then you can scale it down to compensate to keep it within -1 to 1 if needed.

Re: Perlin noise exceeds -1/1 range

PostPosted: Fri May 13, 2016 11:18
by Nore
If that can help, perlin noise will always be less than (1-(persistance^octaves))/(1-persistance) in absolute value; however, it will very rarely get close to that value, if there are a lot of octaves, as it means that all octaves have to be close to 1 at the exact same place. Thus, if you want to rescale perlin noise to a [-1, 1] range, you should use functions such as math.atan to flatten it when the values are too large.

Re: Perlin noise exceeds -1/1 range

PostPosted: Fri May 13, 2016 12:25
by burli
No, I don't want to rescale. I was just wondering because I thought that perlin noise just outputs -1 to 1. But thanks for explanation. Maybe this help others too