Search Unity

[Guide] Procedural World from Voxels in C#

Discussion in 'Community Learning & Teaching' started by KiwyVoxel, Sep 29, 2015.

  1. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello everyone,

    I am working on a project : Voxelab. I want to share what i learned and show you from where. So i started a blog to help gather sources of informations and guidelines if you want to learn about voxels. It is still at the beginning. My goal is to talk about everything that i am using or will use in my project.

    The Guide, content for now, in english and french :
    1. Voxel definition.
    2. Procedural meshing in Unity.
    3. Density function and isosurface.
    4. First chunk in Boxel.
    5. Basic Chunk Management.
    6. Texturing.
    7. Playable mesh modification.
    8. Marching Cubes.
    9. Dual Contouring.
    10. Triplanar Shader.
    Voxelab content, and what will come next in this guide :
    • Multithreaded mesh creation.
    • Boundless World.
    • Dynamic chunk managment.
    • Chunk pooling. Avoid garbadge collection.
    You can look at Voxelab on youtube to see it in action.

    Dual Contouring, Marching Cubes and Boxel​

    Final.jpeg

    If you have suggestions, questions, constructive criticism, or even if you want to share knowledge, don't hesitate to ask here or on my blog.

    If you are curious you can read my guide on voxelab.fr.

    My work is also available on the Unity's asset store : Complete Edition, Meshing Scripts and Triplanar Shaders.
     
    Last edited: Apr 20, 2016
  2. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello everybody,

    The last article of this guide : Basic Chunk Management.

    Sorry for the delay, i am sick since last week and i had to take few days off.
    Next time we finish with the basics with texturing and in-game mesh modification.

    I hope you enjoy this blog.
     
    EliasMasche likes this.
  3. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello,

    Next article on : Texturing.

    Next time in-game mesh modification.
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Definitely going to check it out. Data structures always fascinate me so I'm interested in your step by step voxel instructional.
     
  5. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    I hope it is interesting enough. On the data structures subject i am still experimenting in my project, so i am not sur when i will talk about it.

    The next part of this guide :

    Playable mesh modification.


    This is the last part on the basics of meshing. Next time i will probably start with the Marching Cubes.
     
  6. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Hi, thx for tutorial.

    I need more. I also want to make minecraft likely game.
     
  7. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello,

    A new article on the Marching Cubes algorithm.
    Next one on Dual Contouring.
     
  8. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello,

    A quick note to warn you that there is mistakes in the codes i posted so far. Indeed the plugin i used "Crayon Syntaxe Highlighter" cut when i used code like :

    chunkManager = FindObjectOfType<World>().GetComponent<ChunkManager>();

    to :

    chunkManager = FindObjectOfType().GetComponent();

    So be carefull until i fix this issue.

    btw : when i try to copy past the first line of code from Mono to this post i got a lot of line like :
    ℼ佄呃偙⁅呈䱍倠䉕䥌⁃ⴢ⼯㍗⽃䐯䑔䠠䵔⁌⸴‰
    And it is only if i past it here... wtf ?
    Am i still asleep or missing something very obvious ?
     
  9. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello,

    The renegade code has been vanquished !
    The '<' and '>' was parsed as html marks and was cutting lines only when publishing the articles.
    All posted codes should now be working as intended.
    In any case i gave the full package on the last article on the basics of voxel meshing. If you still have trouble running it please notify me.

    The next article on Dual Contouring is coming soon.
     
  10. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    The article on Dual Contouring basics is ready !
    This algorithm can be a bit difficult to grasp, so i only present the concepts. But if you want to implement your own i linked the best resources that I found : the siggraph papers.
     
  11. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Hello,

    I have written the next article on Triplanar Shader.
    i will probably slow down a bit the publishing so i can concentrate more time on my project.

    I hope it is helping your own project. I would be happy to know if it does.

    See you next time.
     
  12. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    @KiwyVoxel the 7th part Playable mesh modification link is not found, just wanna let u know.
     
  13. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Thank you, post updated :)
     
    ikemen_blueD likes this.
  14. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    55
    This post has been added to my markers tab. :)
    It's suprising the few activity that this post has seeing the good content it has.

    Thanks for made this tutorial, now I will know how to transform my procedural terrain scripts into something cooler.

    Maybe I'm doing something wrong but voxels for Unity are very indocumented. Maybe I'm just searching it with the wrong words.

    Anyway, I want to know if it's possible to make caves with this.

    Thanks.
     
    Last edited: Apr 21, 2016
  15. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Voxel can be a difficult topic and Unity is another layer not based on it. But there are work around. If you have questions dont hesitate to ask.

    You can model any shapes you like, montains, caves, buildings, sculptures, etc...
    This part of the guide talk about that : Isosurfaces

    You are welcome, I am glab it is helping you. :)
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Voxels are just constructs using a mesh. Ultimately, this boils down to understanding the mesh class. Messing around with the mesh base class is usually not trivial. There are some tutorials out there on Voxels and meshes. We have one on procedural cave generation that can get you started thinking about using meshes.
     
  17. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    The Unity's procedural cave generation tutorial is a realy good to start learning :)
    It uses marching squares which is the 2d variant of marching cubes and the basis of Dual Contouring both described in this guide.
     
    Last edited: Apr 22, 2016
  18. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    55
    Yes, you say this: http://forum.unity3d.com/threads/procedural-cave-generation.296986/

    I already reviewed it, but I want to know how can I translate it to 3D and do something like this:



    I downloaded a repository from somewhere one year ago and I try to study it but the code was so complex for me, so, I leave it.

    -----

    It can be easy to transform it to 3D? I'm starting now with voxels and I don't know to much, I downloaded this: https://github.com/thejasonfisher/marchingCubes

    And I'm starting to optimize it and learning how to do terrains based on this and on you guide.

    Thanks to both. ;)
     
  19. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    Marching cubes (MC) uses the same principle as marching square but in three dimension. That said, as you may have seen in the Unity's procedural cave tutorial, you need arrays to store intersections cases.
    Those tables in MC can be tidious to make as there is 256 cases. But as this technique is one of the oldest you can easily find them on internet (the tables and even the complete algorithm). There is a link in the part on MC.

    At first the MC's intersection between two points was defined by the mid point (v.A : 0 --- mid point : 0.5 --- v.B : 1), which give that blocky style. And for demonstration purpose I have shown that method in Voxelab.
    Now in the video you posted, the meshes look much smoother. It is a better solution : linear interpolation. It consists of iterativly cutting the crossed edges in half to find a vertex with a density as cloose of zero as possible.

    As a side note, MC will cut every features not crossing the cubes edges. So it can be good enough for some cases, but if you need a more faithful method there are other options. Like marching tetrahedra, surface nets, and dual contouring.
     
  20. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    @KiwyVoxel any new tutorials? I scan through the 10 tutorials. And, I like the way you explain complex things in much simpler way. I prefer a theory text + a video of actually coding it (explain the code while you do it). But, it is still good the way it is. Btw, your Document link: http://www.voxelab.fr/Documentation/index.html, if I click the Files tab, I can get the full source code of Voxelab for free ;) just want to let you know, so u can either disable that tab or something else.
     
  21. KiwyVoxel

    KiwyVoxel

    Joined:
    Jan 14, 2015
    Posts:
    64
    @ikemen_blueD Fixed ! thanks agains. :)
    I guess people will do with their own morality.

    I think the guide is a good introduction to the voxel world, and if people want to learn more there is a lot of ressources on the web like the SIGGRAPH papers or Voxelab can be of help.

    There is a lot of topics I would have wanted to talk about, but it takes too much work.
    I dont know if I am going to continue the guide, Voxelab did not had a lot of success and I spent way too much time on it.
    Anyway if you have questions about voxels or Voxelab, I still answer to pm, mail at contact@voxelab.fr and here.
     
    ikemen_blueD likes this.