Search Unity

Procedural terrain engine in Unity3D - not the Unity terrain

Discussion in 'Made With Unity' started by MEGATON, Aug 3, 2010.

  1. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    http://www.youtube.com/watch?v=alIZvOAEB6M

    <edit> Added part 2
    http://www.youtube.com/watch?v=Dah7XC8JWXA&fmt=18
    <edit>

    <edit> Added part 3
    http://www.youtube.com/watch?v=_xcNYvlw1AY&fmt=18
    <edit>

    After fives days, I got the basic terrain engine running. The terrain is 20 by 20 km. The heightmap is procedurally generated by use of a perlin noise function, a voronoi diagram, a thermal erosion filter, and some blending techniques. The heightmap wraps seemlessly so the terrain has no borders.

    The next step is texturing.
     
    Last edited: Dec 3, 2010
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Looks like a good start. I'll be interested in seeing how you handle texturing, will that be procedurally done also?
     
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    It's already textured?

    Looks good. I presume you get better framerate with lots of nearby tall cliffs to occlude stuff?
     
  4. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    Looks great! How long does it take to create the terrain at runtime?

    Is this something you could run on iphone?

    Nice work :)
     
  5. BurgZerg-Arcade

    BurgZerg-Arcade

    Joined:
    Jun 22, 2009
    Posts:
    119
    I am not sure you can get a way with a mesh that is divided that many times (to make a decent terrain) on the iPhone.

    Here's hoping I am wrong though :)
     
  6. Xsnip3rX

    Xsnip3rX

    Joined:
    Aug 29, 2009
    Posts:
    197
    Very nice, now make it so it can generate Spherical Heightmaps ^.^
     
  7. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    The blendmap is generated from a perlin function and a voronoi diagram. This blendmap together with a normal map and the vertical inclination angle is enough to create a good enough terrain.

    The view distance is 1000 meters and nothing is purposely hidden behind cliffs. I've lowered the height for the next video preview.

    A 512x512 meta texture is generated at start up by brute force. Unity hangs for 1.68 seconds.

    This terrain engine could possibly run on the combined effort of about 35 iphones. 8)
     
  8. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Nice! Looks a bit sluggish but that could be the recording - how does it perform compared to the standard terrain? Are you using a certain algorithm, ie. ROAM?
     
  9. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    Step 2 of the terrain engine.

    http://www.youtube.com/watch?v=Dah7XC8JWXA&fmt=18

    I've sat for 22 hours updating the engine with textures, sky and water. All the shaders were written from scratch.

    Next step is cleaning up the code and then testing various terrain types,; volcanic, moon, etc

    I've made room for recreating Edolus from Mass Effect.
     
  10. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    The entire terrain is built from about 120 planes. The player is centered in this grid so u see some 40-50% of them at any time. When the player steps onto a new tile on the grid rows of planes are removed and then some added. Each of the new planes are queued for "vertex height displacement".

    I experimented with having three lods on the planes and a view distance of 2 km. That resulted in extra loops when switching plane meshes and the switch was clearly visible on mountain peaks.
     
  11. GorrylIard

    GorrylIard

    Joined:
    May 4, 2008
    Posts:
    44
    I think it looks very good. Very arctic looking landscape.
     
  12. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    Looks AWESOME. Do you intend releasing it to public ?
     
  13. Disati

    Disati

    Joined:
    Oct 5, 2009
    Posts:
    111
    jedybg said what i wanted to say.



    The screenshot looks niiiiice!
     
  14. runningbird

    runningbird

    Joined:
    Sep 3, 2009
    Posts:
    382
    Interesting.... are you releasing this to the public?
     
  15. Novodantis

    Novodantis

    Joined:
    Nov 12, 2009
    Posts:
    95
    Very impressive procedural terrain!

    I will say though, I'm unclear whether the screenshot in your last post is Edolus from Mass Effect or a WiP from this? You may just want to clarify for the humble viewers :D
     
  16. windexglow

    windexglow

    Joined:
    Jun 18, 2010
    Posts:
    378
    How did it take so little time? I'm making one myself yet it takes several seconds for basic results.

    Is it using traditional terrain, or planes with a layer material?

    Any advice to someone doing this for the first time? I have a huge interest in this but haven't found too much online
     
  17. tomnullpointer

    tomnullpointer

    Joined:
    Sep 20, 2010
    Posts:
    142
    Looks great, how are you handling lighting? thinking of using bakd in lightmap/shadowmap? or unitys lighting? Shadowcasting can be a bit tricky i think if you want the terrain to actually darken objects in the shade etc. (not got that far myself)

    Im working on a similar engine, Not implemented chunking yet though. For anyone whos interested in this area of procedural generation Ive put up some info here

    http://www.nullpointer.co.uk/content/?p=189
    http://www.nullpointer.co.uk/content/?p=74

    It was a bit tricker to implement in unity than in raw C++ for me. I was wondering about using the undocumented API for unitys terrain class but since its not stable that could be a problem. The main loss is the build in LOD that unity terrain offers, but with sensible quadtree culling or something I think its an ok trade. It also means you can customise the shader more. I use a rgba texture 4 channel mask to blend 4 tiled textures (in both unity and my own code).
     
  18. Sammual

    Sammual

    Joined:
    Oct 28, 2008
    Posts:
    176
    Any chance I could get the code you use to create your Perlin Noise and Voronoi Diagrams in Unity?
     
  19. Sprocket

    Sprocket

    Joined:
    Sep 18, 2010
    Posts:
    31
    Nice work!

    I have recently started on a similar project myself! Any chance you want to make a webplayer demo available so we can try out your landscape? :)

    A good place to start is LibNoise - an open source (LGPL) project with the most common noise operations:

    Original C++ library: http://libnoise.sourceforge.net/
    C# port: http://libnoisedotnet.codeplex.com/SourceControl/list/changesets
    C# port discussion: http://www.gamedev.net/community/forums/topic.asp?topic_id=502657
     
  20. Nikolay116

    Nikolay116

    Joined:
    Mar 21, 2010
    Posts:
    421
    so what was wrong with the original unity terrain in 2.6?
     
  21. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187

    This is procedural random terrain :p
     
  22. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    Here is a small update on the terrain generator.
    I've added terrain textures. The textures are selected by temperature paramaters generated for the 'planet'.
    Is also has a running daylight system. But that still needs tweaking so there is no focus on that in the video.
    The vehicle - a mining vehicle, is also present in the game.

    Next big step is a spaceship so the player can leave the planet to explore the galaxy.

    See the video here.
     
  23. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    This terrain generator creates a random terrain based on a seed value. The landscape stretches into infinity as it keep creating more terrain in the direction you travel ( and also removing unneeded terrain in the distance behind you naturally. )
     
  24. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    That is very nicely done! I also looked at your planar lighting video, which is also very cool. If you decide to license the procedural terrain code please let me know! :)
     
  25. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Are you using a form of splatmapping for the shader?

    I am making a semi-procedural terrain system for an archipelago. It's not runtime procedural, the heightmaps, splatmaps, detailmaps, and lightmaps are all generated via WorldMachine. Actually I am using USGS heightmap data as the basis in World Machine.

    What IS procedural about it is everything to make the terrain come to life in Unity. The only (huge) drawback is that there seems to be no way I can tell that I can avoid the game "hanging" for 1 second on a 512x512 terrain. I've done all the loading and processing in separate threads but it is apparently impossible to avoid the hang-up when using SetHeights() and SetAlphamaps() because they have to be called in the main thread.

    I really like your procedural world, and it apparently doesn't hang when loading new areas...this makes me incredibly jealous! :(
     
  26. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    The terrain shader selects a texture based on terrain height. There are eight textures per terrain,: Sand( horizontal ), Grass( horizontal/vertical ), Dirt( horizontal, vertical ), Snow( horizontal ), Rock( vertical ). These textures are loaded when the terrain generator starts up and are selected by generated planet parameters. For the blending, I use the heightmap and normalmap to create noise used for blending in between texture layers.
    For the uvs I use shader-based 3-planar uv mapping. See video here
     
  27. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    you rule dude, just been looking through all your stuff. Brilliant!
     
  28. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    subscribed