Search Unity

VOXEL TUTORIAL

Discussion in 'Community Learning & Teaching' started by Reeceg, Jun 11, 2015.

  1. Reeceg

    Reeceg

    Joined:
    May 14, 2014
    Posts:
    30
    Doe anybody know of a good voxel tutorial that is smooth not like minecraft.

    Original thread is in scripting because Im an idiot.
     
  2. vxdcxw

    vxdcxw

    Joined:
    Mar 21, 2014
    Posts:
    15
    I made my own Voxel system (with Dual Contouring) for our previous prototype. First you must know what voxels really are, what are their limitations, when to use them and when not.
    Note that there is a distinction between Voxel datas and a Voxel rendering engine. Minecraft use Voxel datas but not a Voxel RE.

    That said, if you want to learn how to use Voxel rendering in Unity, you should look at "Marching Cubes" and "Dual Contouring" on your favorite search engine. These are algorithms to make smooth mesh through Voxel datas. (there are more algorithms, you can look at too but I don't recommend to learn, plus most are not suited for games)

    If you are a beginner, you should go with Marching Cubes to begin with.

    Here are good readings about Marching Cubes:
    Paul Bourke's: http://paulbourke.net/geometry/polygonise/

    Polytech: http://users.polytech.unice.fr/~lingrand/MarchingCubes/algo.html

    When you feel comfortable, you can go on Dual Contouring (which is a bit more harder to implement). I recommend you to read some articles of "Procedural World", written by the guy behind Voxel Farm.
    http://procworld.blogspot.fr/2010/11/from-voxels-to-polygons.html?m=1

    Upvoid's Devblog also helped me a lot while writting my algorithm.
    https://upvoid.com/devblog/2013/05/terrain-engine-part-1-dual-contouring/

    Be aware that when you are done with the RE, there are a lot of stuff that you will have to handle yourself. You will need to add things such as your own LOD system, octrees, a culling system - since your Voxel mesh can't be static (would be pretty useless), you can't use the Unity culling system - and you won't be able to use lightmaps too.

    Note that there are Voxel pluggins in the Asset store if you don't want to spend the next two months coding, but it won't help you to learn so this is not, IMO, a good solution.

    When you're ready, Happy coding ! ;)
    Hope this helps.
     
  3. Reeceg

    Reeceg

    Joined:
    May 14, 2014
    Posts:
    30
    I have a float array which is what Im putting into marching cubes but how should I edit the array to dig into the voxels?
     
  4. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    digging into marching cubes is not easy because they interact with their surroundings. you need to either apply a sort of diminishing effect from your hit point outwards affecting at least a voxel and its neighbors, or for a click type system I've worked it previously to loop for -1x to +1x for x,y,z and change all the densities from whatever to -1.

    if you only affect one you won't generally see any effect. but it's not that hard to do until you get into multiple meshes.
     
  5. Rick Love

    Rick Love

    Joined:
    Oct 23, 2014
    Posts:
    76
    @Mouton Thanks for this!

    I've been wondering about this for a while and your overview straightens everything out. (like "How can an infinite voxel world be rendered quickly?")

    Here is a question that remains:

    How would you implement physics in a voxel world?

    Have you experimented with a way to promote some blocks to actual game objects so that the built in physics could be used (say for example if the blocks are close enough to the player, on the surface, etc.)?
     
  6. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    physics work just fine with voxels. the term "voxel" is just a data point on a 2d/3d grid, but usually we're talking about building a mesh based off that data. with a proper mesh you've easily got a collision mesh, as is the case with marchingcubes or minecraft like worlds. you can even seperate "chunks" or meshes to be their own object not necessarily limiting the voxels to terrain. They can then be treated as any other meshed object.

    VoxelFarm for one has shown this openly. breaking off parts of buildings, seperating the removed mesh onto itself (I assume) and letting it crumble.
     
  7. Minja

    Minja

    Joined:
    Dec 5, 2014
    Posts:
    3
    I have tried to implement DC, but I gave up :/ Does anyone have a working octree DC implementation he is willing to share? I can offer beer... This algorithm is driving me crazy
     
  8. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I never figured it out either =[

    earlier in the year birthed from my distaste for the look of marchingcubes I wrote some of my own stuff basically moving the four corners of a cube on its top to line up with a noise algorithm. makes for a very easy to implement smooth surface. if you try to move that into three dimensions it gets extremely difficult though.

    you can also smooth the densities of marchingcubes with their neighbors for very smooth effects. doesn't work well when you start digging and placing though. and is a bit processor intense