Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to Smoothly merge two PerlinNoise

Discussion in 'Editor & General Support' started by Dannark, Apr 12, 2018.

  1. Dannark

    Dannark

    Joined:
    Jul 24, 2016
    Posts:
    14
    Hello there,
    I'm working on a minecraft style game just for hobby and study reasons.
    The thing is, i've been trying to achieve this as best as i could but the result isn't looking anygood.
    The idea is to merge let's say a Mountain biome with a flatland biome

    Right now the map chunks(Montain biome) are generated around the player, as he walks, once the camera reaches 100 meters of distance from the center it will start drawning the flatland biome.

    this is my Mountain PerlinNoise setup
    Code (CSharp):
    1.  
    2. if (bioma == Bioma.Mountain)
    3.         {
    4.             freq = 300;
    5.             amp = 50;
    6.  
    7.             float o1 = (Mathf.PerlinNoise((offSet.x + x) / freq, (offSet.z + z) / freq) * amp);
    8.  
    9.             freq = 100;
    10.             amp = 50;
    11.             float o2 = (Mathf.PerlinNoise((offSet.x + x) / freq, (offSet.z + z) / freq) * amp);
    12.  
    13.             freq = 30;
    14.             amp = 20;
    15.             float o3 = (Mathf.PerlinNoise((offSet.x + x) / freq, (offSet.z + z) / freq) * amp);
    16.  
    17.             maxY = Mathf.RoundToInt(o1 - o2 + o3);
    18.         }
    19.  
    And my Flatland:
    Code (CSharp):
    1.  
    2. if (bioma == Bioma.Flatland){
    3.             freq = 100;
    4.             amp = -20;
    5.             float o1 = (Mathf.PerlinNoise((offSet.x + x) / freq, (offSet.z + z) / freq) * amp);
    6.  
    7.             freq = 35;
    8.             amp = 5;
    9.             float o2 = (Mathf.PerlinNoise((offSet.x + x) / freq, (offSet.z + z) / freq) * amp);
    10. maxY = Mathf.RoundToInt(o1 + o2);
    11. }
    How it looks without mergering
     
  2. Dannark

    Dannark

    Joined:
    Jul 24, 2016
    Posts:
    14
    In order to get the the biomes merged I've tried using both values, reducing one as the other grows like:

    (MountainValue *0.1f) + (FlatlandValue * 0.9f)
    (MountainValue *0.2f) + (FlatlandValue * 0.8f)
    (MountainValue *0.3f) + (FlatlandValue * 0.7f)
    (MountainValue *0.4f) + (FlatlandValue * 0.6f)
    ...
    (MountainValue *0.9f) + (FlatlandValue * 0.1f)

    it did almost work, but the result was very weird, so i'd like to hear some ideas :D thx
    How it looks without mergering

    With my current mergering:
     
    Last edited: Apr 12, 2018
  3. Dannark

    Dannark

    Joined:
    Jul 24, 2016
    Posts:
    14
    Well i did it with Mathf.Lerp, not perfect but it worked
     
  4. trepan

    trepan

    Joined:
    Feb 11, 2011
    Posts:
    113
  5. Dannark

    Dannark

    Joined:
    Jul 24, 2016
    Posts:
    14
    Very interesting, definitely something i have to checkout, we never know what ideas might come up in the future hahaha