Search Unity

C# Planet Generation w/ Perlin Noise

Discussion in 'Scripting' started by Plexus1, Mar 9, 2014.

  1. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
    Hi, I want to make a planet generator using perlin noise that can support biomes, resources, mining and building. I don't want the terrain to be like Minecraft with cubic voxels but rather implement something like marching cubes. I've done my time googling and found a few interesting sources:

    http://forum.unity3d.com/threads/127292-Procedural-Terrain-on-a-Planet
    http://www.youtube.com/watch?v=OQu73MNvx48&list=UUsxheFH1H9S7qCyENJ7PzHA
    http://www.youtube.com/playlist?list=PLW2i42bgplOmRWRmo116mUA4N9-i17dIk

    How should/can i make this in unity for the game I am making?

    Thanks in advance!
     
    Last edited: Mar 9, 2014
  2. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Sure you can, as a matter of fact, I myself am creating something like that:
    $7nC7s.jpg

    Creating an actual round planet instead of a simple flat plane is actually quite hard. Your best bet to this would be 'faking' the illusion by using a shader that makes the world look round. Unless you want to get into actual space exploration and such, you dont need to make it actually round, as this would also require you to implement your own physics (really hard).

    Also a good reference if you want to go the round planet way:
    http://www.youtube.com/channel/UCMlW2qG20hcFYo06rcit4CQ

    And a general recommended article from GPU gems:
    http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html

    How hard it is to assemble, depends on what you want to accomplish though. Do you want unlimited in the horizontal direction? Also in the vertical direction or is a limit good enough for you? Like mentioned before, do you want to include space exploration? The more you sacrifice the easier it gets with voxel terrains in general and the more you can simplify, allowing better performance. Take your time to think for yourself what you really want and what not. For example, I decided to ditch the space exploration and work with a horizontal 'plane' of world, but would like infinite in all direction if that is still feasible with other features.

    EDIT: also read the 'after playing minecraft' thread in the gossip section, this will give you a good overview of what's involved in what features.
     
    Last edited: Mar 9, 2014
  3. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
    Thanks for the quick reply! Indeed I want several planets and space exploration, also it has to be capable of multiplayer and I don't want it to be infinite terrain, so I cant really "fake" the roundness of a planet. I have read the After playing minecraft thread. But it isn't really explained well. Nice screenshot btw, that is something similar to what i want to make and also the Seed Of Andromeda looks awesome that is definitely something similar to what I want to make!
     
    Last edited: Mar 10, 2014
  4. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
  5. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
    Does anyone have any other ideas?
     
  6. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    I remember completing a solid planet generator. The concepts bordered on Spore's planet generator.

    It has been a while since I tinkered with any of that though. The concept was simple, take a cube and make it a sphere. One simple mathematical statement.


    Code (csharp):
    1.  
    2. Vector3 point = currentpoint.normalized * radius + heightOffset;
    3.  
    This means that if you have a side that is 100x100 quads each point is defined in the space of a cube. All you then have to do is to have a height map that corresponds to that grid. 6 grids, 6 sides all using that statement and you get a planet.

    I think this is one of those things that warrants being put up on the asset store at a later point. Perhaps after I am done with the two current projects for there.
     
  7. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
    Ok this seems simple enough, but how would I make this volumetric if it using height maps.
     
  8. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Thank you :)

    You probably have 2 options here:

    Either use radial grids (google them), although I have no idea how the implementation will look like, how performant it is and can imagine that it gets quite complicated. I would call this the 'real' way.

    Or you can go the Seed of Andromeda way, which is storing the 6 grids bigmisterb talked about and treat them like normal horizontal grids. Then manipulate the meshes etc to account for the round planet. This has some problems. For instance, when you decide to make an 'infinite' depth in each of the grid faces, when you dig further down than your planet diameter, you wont pop out on the other side of the planet. Instead your depth is really infinite, which is something difficult to wrap your head around. Of course making the planets very large minimizes this problem. Another problem is, what Ben calls, the 8 corner problem. He has a video about it explaining it pretty clear here: https://www.youtube.com/watch?v=vQektfK1kco
    There is also a part 2. He also mentions the other problems with this approach
     
  9. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    The whole thing revolves around a cube map. I would make a simple cube map and have the corresponding edges always match. So when you change 0,0 on the front, then you also have to change 0,n on the top and n,0 on the left.

    Makes it simpler that way.
     
  10. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26
    I will most likely go the Seed Of Andromeda way, as it is simpler. The problems that come with it don't really bother me at this stage. I have made a cube normalize to a sphere. What should I do now? Thanks to all of you for your helpful posts.
     
  11. Plexus1

    Plexus1

    Joined:
    Mar 9, 2014
    Posts:
    26