Search Unity

Procedural Voxel-based Terrain

Discussion in 'Works In Progress - Archive' started by LSpring, Dec 4, 2014.

  1. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Infinitum_19.jpg

    Infinitum_21.jpg



    EDIT: UPDATED TO INCLUDE MORE RECENT PICS AND A VIDEO (ABOVE) IN THE FIRST POST

    I've been looking at all sorts of commercial and non-commercial solutions for terrain environments and nothing seemed quite right for what I wanted. After a LOT of "auditioning", I decided to roll my own custom solution.

    Credit where it is due, scrawkblog.com was a great resource with code examples for getting into the guts of what I needed to do. I have a pretty deep background in rendering, but for the sake of expedience, a couple of algorithms were "borrowed" whole cloth, so thanks! :D

    Anyway, here are some pics of a first pass at generating and rendering some procedural terrain in Unity. The intent is to create compelling environments for our conversational AI driven characters to interact with players.

    It's not where I want it to be yet, but I feel like I've got a good start on a customizable procedural system.

    Cheers.
     

    Attached Files:

    Last edited: Aug 29, 2015
  2. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    The texturing looks very nice. Will be interested to see how the project progresses. Good luck :)
     
  3. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    Awesome!
     
  4. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Looks nice! How did you manage to get the blending between materials so clean? or is this just a single 'material' with seperate top/side/bottom triplanar mapping?
     
  5. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Thanks for the feedback everyone. It is a WIP, but I'm happy enough with the foundation.

    wasstraat65, I am currently using a single custom material/shader for the entire scene (excepting the skybox of course). The shader does use triplanar mapping for determining texturing coordinates, but has more complex parametric rules for blending various surface types so that I don't need large color (splat) maps for each terrain.

    Those screens were captured running 60fps at 1280x720 on an old machine with a GTX 555M processor, so performance is good so far. We'll see what happens when I start adding more features.
     
  6. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Just to reiterate, your blog is a fantastic resource. Well done.
     
  7. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Yeah like I thought. Have you thought of a solution to yet to blend several voxel types smoothly together? I currently only have hard edges between seperate voxel types, which are caused by using one submesh for each voxel type
     
  8. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    If you mean what I think you mean...

    Currently, the voxels themselves don't have much effect on surface type(s). This is mostly determined parametrically at the shader level, so blending is handled procedurally.

    That said, I am looking at embedding additional controls for the shader(s) into unused parts of the mesh vertex data. In particular, I'm interested in smooth transitions between multiple procedural shaders in order to sync up with large changes in terrain type. Maybe a multipass render for blending materials.
     
  9. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Here are some new images with improvements to terrain generation and shaders. Specifically, more surface types and controls in the shader, multi-uv support, and more complex terrain generation algorithms.

    More accurate lighting too.
     

    Attached Files:

  10. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Kind of a big update. But I wanted to show some more features including auto-generation of winding paths into the hills, support for more layers in the shader, multi-uv blending that preserves color and surface normal richness, a more realistic look in general, more layers of mountain strata, snow at higher altitudes, etc.

    Side note: In all of the screenshots I have posted, I am basically "exploring" the generated terrain in first-person mode.
     

    Attached Files:

  11. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    ... continued.
     

    Attached Files:

  12. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Here are some images of the latest and greatest.

    I've optimized terrain generation, fixed bugs in the process, and I now have more intuitive layered parametric controls in the procedural terrain editor.

    I have also moved ALL terrain surfacing decisions to the pixel shader. Mesh vertex color data is now free to use however I see fit.

    Visually, texturing is much improved as are terrain geometry features. And what should be obvious, I now have added controls for automatic procedural placement of objects such as trees, shrubs, rocks, and even water.

    I had problems picking screen shots this time because with all of these fixes and improvements, no matter where I go in the world every shot is a beauty shot. Also, there seems to be a painterly quality to some of these shots that I like.
     

    Attached Files:

  13. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    ... continued.
     

    Attached Files:

  14. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    This is probably a stupid question, but if I don't ask I'll never know,
    What classifies this as 'voxel-based'? A general answer will suffice, I'm an animator. :)
     
  15. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    It's a good question.

    Most terrain systems work in 2D space, where one or more 2D maps are generated and/or painted to define the terrain features. At least one of these maps is applied to a grid mesh of polygons to raise or lower individual points in the mesh as determined by the maps. Unity's built in terrain system works this way.

    However, in a voxel-based terrain system:

    1) Density values are created in a 3D grid space (voxels) instead of height values in a 2D map space (pixels).

    2) For each voxel at a given 3D coordinate, the density value can be "solid", "empty", or something in between.

    3) If a voxel is "solid", no polygons are constructed in that voxel. It is completely "inside" the terrain.

    4).If a voxel is "empty", no polygons are constructed in that voxel. It is completely "outside" the terrain.

    5) If the value is in somewhere in between, it contains a boundary between solid and empty that has to be calculated and rendered.

    6) Using values at each corner of any "boundary" voxels, one or more polygons are calculated and created that conform to the density changes between that voxel and its neighbors.


    In simple terms, because voxels are computed in all three dimensions of space instead of the two dimensions of a flat height map, they allow for things like caves, overhangs, and other true 3D geometries to be more easily and automatically created as part of the terrain generation process.

    I hope that helps.
     
  16. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Thanks a lot Cognitive. I think I actually understand. o_O believe it or not.
    Great explanation.
     
  17. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Instead of a load of new images, here is just one. Enjoy.
     

    Attached Files:

  18. EBR

    EBR

    Joined:
    Jan 27, 2013
    Posts:
    117
    Looks good, I have also been looking into voxel terrains with the help of the scrawkblog and other resources. :)
     
  19. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    We're finally approaching more realistic results better suited to the game we're developing. The game design requires a "rocky desert" theme and now we're finally getting there.

    (see attached image)

    Technical stuff: By switching to a lower resolution voxel grid, but augmenting with noise displacement and more detailed textures, we are getting overall better visual quality and greater distance views. Voxels are still converted to mesh data, but that mesh data is much more low res so we can hold larger terrain areas in memory.

    With fractal noise, lower resolution voxels introduce more noticeable "terraces" (think Minecraft). However, adding a noise-based displacement mitigates this problem enough for our needs.

    The terrain textures are from Yughues Free in the asset store (a total of 4 diffuse+normal maps used in this scene). The 1K resolution in these textures certainly helps. The rest of the scene is completely procedural (no hand editing).


    For "infinite detail" I would like to someday use image-space pixel shaders like this:

    https://www.shadertoy.com/view/lsf3zB

    https://www.shadertoy.com/view/Xls3D2

    Alas, it would be quite a time-consuming feat to integrate typical Unity gameplay elements with a non mesh-based solution like this. :(
     

    Attached Files:

    Last edited: Apr 25, 2015
    MD_Reptile likes this.
  20. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    More desert scenes. DesertTerrain_08.jpg DesertTerrain_09.jpg DesertTerrain_10.jpg
     
  21. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    can you change the terrain in real time or its a static one
    Amazing stuff
     
  22. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Yes, the terrain is dynamic. The voxels and meshes can be regenerated or modified at any time during gameplay.

    However, we're not necessarily going to support Minecraft-like editing. We're focused on developing a realistic adventure game with massive (virtually infinite) terrains, so for this game, the player will probably not have direct control over terrain features.

    Having a visually appealing and high-performance open-world terrain system has made everyone rethink design in order to take advantage of the almost unlimited exploration that can now be done.
     
  23. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    By the way, aside from making progress on our terrain solution, something very important happened between the screenshots posted on Dec. 17, 2014 and the screenshots posted starting last Friday April 24, 2015.

    I won't make you guess: we switched over to Unity 5. The difference is obvious.
     
  24. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    One more screenshot before bed. DesertTerrain_11.jpg
     
  25. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    the trees and grass ect that are placed, are they prefabs or do you use unitys terrain placing
     
  26. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    They're prefabs and/or meshes with materials. I can't use Unity's terrain placement because the ground is made up of non-terrain meshes. I also now have rock placement happening based on ground types and the rocks use gravity to fall and collide properly with the terrain. No "floating" or unbalanced looking rocks.
     
  27. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    what about adding a water plane? how easy/hard do you think it would be like have small ones placed in different areas (lakes/puddles)
     
  28. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    The most recent focus has been on simulating a dry desert world for a particular game, but if you look at posts #12 and #13 you'll see where we added landscapes with water.
     
  29. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Wow those desert shots look awesome! Definitely some good work so far, and I'm curious, what is the project your going to use this with? Is that announced yet?
     
  30. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Thanks so much. One of the best compliments I received was when a non-gamer friend saw some of the recent images and asked where I took the pictures. I had some difficulty convincing her that I hadn't somehow posted a touched up digital photo of a real desert.

    As for the project, we're building an as-yet unannounced game that utilizes these open worlds. At a high level, the game we're building is a massive exploratory adventure.

    We're at the point where we have a fairly complete playable "Chapter 1" that looks, sounds and plays more like a shipping title than a demo. The world can expand indefinitely as the player explores, but we also have developed quite a bit of game content for the player to discover and interact with including structures, vehicles, characters, etc.

    I really can't talk too much about the project but we seem to be on the right track because we're having trouble pulling people away from our testing builds.
     
  31. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    An in-game screenshot using the procedural world generator. We also have a new procedural road generation system and the terrain auto-conforms in real-time to the roads.

    Infinitum_15.jpg
     
  32. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Another one.

    Infinitum_16.jpg
     
    Jamster likes this.
  33. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Wow, this looks really amazing! Do you think you will ever sell this on the asset store? Because by the looks of it its really versatile, and I think it could be worthwhile for you to do so, a lot of people would get it
     
  34. IAmCraigSnedeker

    IAmCraigSnedeker

    Joined:
    Jul 20, 2014
    Posts:
    117
    This looks amazing!

    I love how the textures on vertical surfaces aren't stretched.
     
  35. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Thank you.

    Unfortunately there is too much going on for us at the moment, what with the game and related new technologies in development. We're also supporting our existing customers for our AI system, and we have some other positive developments that are taking our time and energy to move forward.

    So at this time we simply don't have the bandwidth to properly support a release in the asset store.
     
  36. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Thank you as well!

    Triplanar texturing can do a lot, but part of our method is to do some additional procedural processing and tessellation on the geometry after we have already derived any output mesh(s) from the voxel data.

    This post processing is especially important when other geometry (such as a curving road) does not align to voxel boundaries and the terrain must auto-conform "after the fact" with that other geometry.
     
  37. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    That looks absolutely amazing, well done! There's some very exciting work regarding POM I'm privy to coming to unity soon that might really enrich your surfaces so eyes peeled, I'm kind of sad I have to somewhat 'roll my own' to get this kind of thing going when I covet it so much aha
     
  38. drizztfun

    drizztfun

    Joined:
    Jul 2, 2013
    Posts:
    25
    hi there

    even you said there is no time for a proper asset store release i wanted to tell that i am interested too :)
    Always looking for a voxel-terrain which can handle it all.. being beautiful, fast and flexible
    Something that can handle big terrains but is also able to make some details without making them look like a 2 year was on a rampage.
     
  39. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Here is an update on video so you can see it in action beyond the stills.



    Thanks again for the feedback. Sorry about no release on the asset store but I'm too focused on advancing the tech for the game itself. Cheers.
     
  40. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Another fun screenshot. Going for a sci-fi "concept painting" brought to life.

    Infinitum_19.jpg

    Side note, biomes are now implemented. This game (or at least the first episode) takes place in a rocky desert landscape, but even there, biomes add more variety. I'll post some captures soon to show these in action.
     
    MD_Reptile likes this.
  41. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Everything dynamic in the game world is linked to the passage of time. Here on the dawn of the next day, the sun is about to rise behind us.

    Infinitum_20.jpg
     
    roryo likes this.
  42. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    I'm super impressed. Not sure how I haven't seen this until now. Following your progress!
     
  43. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Thanks for the kind words! This has been quite a journey so far, one I've been enjoying.

    Here's a new image from fairly high up, with some mesa-producing layered erosion added to the mix. Various erosion factors are computed at run-time and applied to the terrain as it is generated during gameplay. Also note that with this high-altitude view, we can see the smooth biome transition from this nearby "canyon country" to the rocky desert in the distance.

    Infinitum_21.jpg
     
  44. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    Another shot of some rock formations that have an "American Southwest" feel.

    Infinitum_23.jpg
     
  45. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    A long-distance beauty shot.

    Infinitum_24.jpg
     
  46. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Definitely rad.

    I'd like to see more video; particularly the scene in #41.

    If you have some time, I'm sure many of us would like more of an idea what the purpose of this game is?
     
  47. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    When I started this thread, I was focusing on basic terrain generation. I suppose that since this project has evolved into a working game under development, I'll post something with more gameplay soon. In the mean time, words.

    In a nutshell, the game is a story-based open world adventure.

    One key element is the game's truly conversational characters. When playing, one simply approaches characters and talks with them. Through spoken conversation, you learn more about the world, solve puzzles that help move the game forward, and even gain companions that accompany and guide you through different parts of the adventure.

    The other key element (which I hope comes across in the images) is the compelling immersive nature of the world itself. Because this is an "indie" game, we don't have a massive art, music, or programming staff, so we're pushing procedural content generation in a direction that is as "AAA" and as "artistic" as possible.

    The game is designed to appeal to people who like science fiction stories, adventures, artificial intelligence, virtual sight-seeing and solving mysteries.
     
  48. LSpring

    LSpring

    Joined:
    Nov 12, 2014
    Posts:
    68
    An updated visual video. I've added complexity to the eroded "rocky" terrain with a biome overlay that introduces, among other things, cliffs, mesas and more complex texturing, as shown in the stills in posts 43-45.



    The next video will show some player conversations with AI characters.
     
  49. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    Really enjoyed this video! Thanks for updating us.
     
  50. moure

    moure

    Joined:
    Aug 18, 2013
    Posts:
    184
    Hey, nice videos :)
    How do you plan to fix the frame rate drops due to chunk loading/changing lod levels? Would it help if you moved the generation and loading of chunks to other threads?