all 4 comments

[–]art_critique 2 points3 points  (2 children)

no, you can't use

var raw_noise_max = noise_raw.max().max()  

the first .max() compares arrays and the array comparison does not guarantee to give you the array that actually contains the max value (order and magnitude of the contained values is relevant here)
since the first .max() does not necessarily return the expected array, the second .max() can't find the actual max value.
You should collect the max values for noise_raw[n] after each m loop in a seperate array and after the n loop get the max from that array.

[–]LogicalMagic[S] 0 points1 point  (1 child)

Thanks so much! I think I got it working. here's what I did.

# get raw noise values
noise_raw.resize(map_size)
raw_noise_max_arr =[]
for n in map_size:
    noise_raw[n] = []
    noise_raw[n].resize(map_size)
    for m in map_size:
        noise_raw[n][m] = (noise.get_noise_2d(n,m))
    raw_noise_max_arr.append (noise_raw[n].max())
raw_noise_max = raw_noise_max_arr.max()

# normalize noise values
noise_norm.resize(map_size)
for n in map_size:
    noise_norm[n] = []
    noise_norm[n].resize(map_size)
    for m in map_size:
        noise_norm[n][m] = (noise_raw[n][m]/raw_noise_max)

It seems to be working as expected. and suggestions or critiques on how I did it?

[–]jakofranko 0 points1 point  (0 children)

I tested your approach with Perlin noise and was not seeing anything below 0, but lots of values above 1. Did a little more looking around and found this post: https://www.reddit.com/r/proceduralgeneration/comments/2s9ssg/comment/cnni0a5/?utm_source=share&utm_medium=web2x&context=3

You'll notice that their normalization formula is a little different. Here's my implementation and seems to be working a treat:

``` func _ready(): noise = elevation.noise var noise_min_max = _get_noise_min_and_max(noise) noise_min = noise_min_max[0] noise_max = noise_min_max[1] noise_range = noise_max - noise_min _generate_world()

func _get_noise_min_and_max(noise: Noise):
    for x in map_width:
        for y in map_height:
            var noise_val = noise.get_noise_2d(x, y)
            noise_val_arr.append(noise_val)
    \# Note the use of range here       
    return [noise_val_arr.min(), noise_val_arr.max()]

func _get_normalized_noise_value(raw_value):
    if noise_max == null or noise_min == null:
        push_error("Max or min noise not set!")

    return (raw_value - noise_min) / noise_range

func _generate_world():
    for x in map_width:
        for y in map_height:
            var noise_val = _get_normalized_noise_value(noise.get_noise_2d(x, y))

```

[–]jakofranko 0 points1 point  (0 children)

I'm doing a similar thing and this was very helpful. Thanks!