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. Dismiss Notice

Need: High Quality Terrain To Be Procedurally Generated At Runtime

Discussion in 'General Discussion' started by EternalAmbiguity, Feb 17, 2015.

  1. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    So I'm planning a game where each time the player starts, it will be a new map. I'm thinking I'll either have the player be able to select things like elevation, number of rivers, mountains, etc. or (more likely) just have a seed field where they can type in a number, and generate a terrain based off of that.

    Thus, I need a way to procedurally generate terrains on the start of a game, that allows me to control all the features of the procedural generation, and allows me to tie all of those to a seed value. This terrain needs to be a very large size (may need tiling), with a high resolution.

    Any Asset Store (or otherwise integrated with Unity) suggestions?
     
  2. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
  3. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    To have some control over the outcome, I'd maybe use a subdivision algorithm. You can then say how many mountains you want, ie each mountain is a starting point in a very coarse grid, then gradually subdivide it with randomness to various levels. Then build the mesh from it.
     
  5. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I think you can generate at runtime, as far as I know, I haven't played with that.
     
  6. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    i just checked over there and the creator confirmed that it was doable. I think I'm gonna go for it. Thanks again for the suggestion (and thanks for yours as well, imaginaryhuman).
     
  7. SkavenPlanet

    SkavenPlanet

    Joined:
    Jan 20, 2014
    Posts:
    33
    If you're not familiar with perlin noise, fractal-brownian motion, and cell (voronoi or worley) noise then definitely check those algorithms out as they can be seeded as you described and can be used to produce hills, mountains, plateaus, etc via some level of modulation. Procedural rivers are a little tricky but something akin to an L-system connecting points generated by a space colonization algorithm superimposed on the heights generated by the noise may work. If you have pro you should investigate generating your terrain heightmaps on the GPU, converting the heightmap render texture to a 2D texture, and using GetPixels() when you displace the vertices of your terrain. This way you can use rather complex heightmap generation algorithms without severely impacting framerate (all depending on if you're system requires heightmaps to be generated at runtime). Generating heightmaps on the GPU also allows you to create (relatively) high-res normalmaps from a heightmap which significantly improves the quality of the terrain. If you're not intending on using the built-in terrain and instead generating your own meshes then you're most likely also going to need to implement a quadtree subdivision LOD system (which the built-in terrain already has) which can be a lot of hassle but is definitely doable.
     
  8. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    I've heard about all of those, though I don't have a lot of knowledge into how they work.

    For rivers I figured I'd just have the water element of the game set up to start at some certain height on the terrain, so all heights below that would be underwater.

    Do not have Pro, unfortunately.

    I plan to use TerrainComposer. I'm not sure if that uses the built-in terrain or not.
     
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,071
    You could take it one step further by implementing the water as another terrain element that sits slightly below the land terrain. Then when you need water to appear, simply lower the land level to slightly below the water level for a specific point.

    World Machine strikes me as the more ideal choice for this style as you can have it set to export the water terrain levels prior to executing the phases that produce rivers and other water bodies.
     
  10. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Can that be done procedurally? That seems like a manual step.
     
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,071
    Oh right. Runtime. I must have confused this thread with the other. Granted you could do it procedurally by cloning the terrain before producing rivers and lakes.

    Edit: Yep. There's the thread down near the bottom of the list. :p
     
    Last edited: Feb 23, 2015
  12. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144