Search Unity

Defining regions/areas in TerraVol [Region system help]

Discussion in 'Scripting' started by z3nth10n, Nov 24, 2014.

  1. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    55
    Hi, well I'm using Terravol for generate volumetric Terrains, I'm following all the Doc's steps, now I'm trying to do a biome system, the problem is that the docs doesn't say anything about how can you do complex region system for define your biomes. I started to think how to do it, but the problem now is how can I define a area to assing the biomes and how can I get the biome on a given point, as the example does.

    The idea

    For example I can define a regular square grid or a irregular rectangle grid, an example could be this:



    Now I define all the biomes:



    Once the biomes are defined, now I want to know the biome on a given points:



    Red point (it's a random position) returns biome "C"

    Green point returns "B"

    And blue point returns "A"

    The docs give an example:

    Code (CSharp):
    1. if (position.x > 50)
    2.    return "WinterDefault"; // WinterDefault block will be used
    3. else
    4.    return null: // Default block will be used

    But this example was made with static values (50), I need to know how can I do this dynamical...

    So, can somebody give me an example or guide me to do this?

    Thanks in advance.

    Bye.


    PS: Sorry for bad english. :/

    PS2: I don't know how can I figure this out, so for this reason I didn't put any code. Sorry. :/
     
    Last edited: Nov 24, 2014
  2. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    198
    I will try to explain this but I don't own Terravol (I rolled my own Voxel DC terrain engine). What you need to do is essentially generate a Biome Map in the same way you would generate terrain.

    So given a Noise function, ie Noise.GetValue(x,y,z) = a (where a is the returned noise value between 0f and 1f).
    Given a Vector2 BiomSize variable that describes how large you want your Biome to be in Voxels for given BiomeMap grid location.

    The equation to get a biome index would be something like this for a given Vector3 location (the location you are trying to calculate the biome for)

    int maxBiomeIndex = 3 (maximum index of the biome, so for biomes A,B,and C that would be 3)


    var biomIndex = Mathf.FloortoInt(Noise.GetValue(Mathf.Floor(location.x/BiomSize.x), -10000f, Mathf.Floor(location.z/BiomSize.y))*maxBiomIndex);

    then you basically just return the correct Biome for that index (in this case an index from 0 to 2)
    switch (biomIndex){
    case 0: return A;
    case 1: return B;
    case 2: return C;
    }

    Note that I set the y parameter to -10000, this really could be any y but it should be the same y everytime.

    All that said, once you do this you are going to have other issues (which is why biomes are harder to do correctly than they appear). Assuming you use differing procedural algorithms to generate the terrain (perhaps different parameters to the Noise function, etc), then your terrains won't match up (you'll get sharp cliffs when you approach a biom change) unless you account for the transition from one biom to another and possibly Lerp between them during this transition.
     
  3. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    55
    I'm very grateful for your answer (I thought that nobody would answer), with the information you gave I started to search about Perlin noise, and well now I have this:



    I only have a problem and is that these biomes are based on height, and well, I would like to do it more like this:



    Do you have any idea of where can I find any example of this kind of Pelin noise?

    Any link, example or help would be fantastic ^^

    Thanks in advance.
    And as I said before, thanks for your answer. :)
     
  4. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    55