Perlin Noise Results always concentrating around 0.5

  1. What do you want to achieve?
    I want to create a field generator to generate fields like in the game “Bee Swarm Simulator”. They always have the same layout and to achieve that, I am using the Perlin Noise Function. I also added weights, meaning hat if the Perlin Noise Number is in the range from 0 to 0.3, it generates Red Flowers, from 0.3 to 0.6 White Flowers and from 0.6 to 1 Blue Flowers. The range can be changed to adjust the amount of flowers in the field, at least that’s how it should work

  2. What is the issue?
    The issue is that the results concentrate around 0.5. This is especially an issue with the weights system, because the Perlin Noise Numbers are not equally spaced between 0 and 1.

So in short: My problem is that instead of being equally spaced between 0 and 1, the Perlin Noise Numbers are concentrated near 0.5, which breaks the system and makes it impossible to add weights.

local function ChoooseFlower(Field)
    local FieldSettings = Settings.FieldSettings[Field.Name]
    local FlowerWeight_Blue = FieldSettings.BlueFlowerWeight
    local FlowerWeight_White = FieldSettings.WhiteFlowerWeight
    local FlowerWeight_Red = FieldSettings.RedFlowerWeight
    -- All weights add up to 1

    local Seed = 0.2143
    local PN_Number = ((math.noise(FieldGenX, 0, Seed) + 1) / 2)
    
    if PN_Number <= 0 or PN_Number >= 1 then
        error("Perlin-Noise-Error --> PN_Number: "..PN_Number)
    end
    
    FieldGenX = FieldGenX + 1
    
    if PN_Number <= FlowerWeight_Blue then
        return FlowersPresets.Flower_Blue:Clone(), PN_Number
    elseif PN_Number >= FlowerWeight_Blue and PN_Number <= FlowerWeight_Red then
        return FlowersPresets.Flower_White:Clone() , PN_Number
    elseif PN_Number >= FlowerWeight_Red then
        return FlowersPresets.Flower_Red:Clone(), PN_Number
    end
end
1 Like

Hey GermanKnight!

You are taking the average of two numbers (x + y) / 2 = z (i.e. (0 + 1) / 2 = 0.5
Calculating the average of the perlin noise output and the number “1” skips over values less than 0.5 in this code.

You should try a different formula here.

Hey, thanks for your answer!
Do you have an idea for a different formula? I am not very good at math. I only use that because I have no idea how apply the weights system to the normal Perlin Noise range from -1 to 1, because I have to split this up into three parts.

Yes, you can calculate them to range 0 between 1 like

(math.noise(x,y,z) / 2) + 0.5

Or you could change the flower weights to work with values between -1 and 1, both solutions should work in this case!

1 Like

Okay, so I’ve included your formula and shifted my range to only from 0.35 to 0.65, and I have to put in numbers higher than 1 so everything matches up higher than 1, but it works and I am fine with that. Thanks for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.