[WIP] Voxel Meshing

Hello everyone,

I am glad to present to you my work : An exemple of procedural meshing based on voxel. It include the Dual Contouring, Marching Cubes and “Minecraft like” (Boxel) algorithms. Also an implementation of constructive solid geometry that allow easy construction, modification and destruction of meshes.

Try it

Dual Contouring


Marching Cube

Boxel

Content

  • C# and Unity 5.0.1f1.

  • Dual Contouring algorithm. One rather faithful and quick technique, with sharps edges, used in Voxel Farm (and everquest next).

  • Marching Cubes algorithm. SIGGRAPHE 1987, base of multiples algorithms (including DC).

  • Boxel algorithm. Simple meshing technique well known because of Minecraft (helpfull for learning).

  • Multithreaded mesh creation.

  • Isosurfaces : Constructive Solide Geometry, heightmap, simplexe noise, sphere, cube, plane. Densities functions (f(x) = d, if d > 0 out of the mesh, d < 0 in the mesh).

  • Basic gameplay to create surfaces. Union, difference and intersection for constructive solide geometry.

  • Boundless World.

  • Chunk manager and game manager. Based on Finite State Machine for code lisibility. Dynamic chunk managment.

  • Chunk pooling. Avoid garbadge collection.

  • Basic character controler.

Triplanar Shader (XZ / +Y / - Y axis)
Try it


Shaders Content

  • 18 Surface shaders based on vertex position and surface’s normal (Triplanar).
  • Based on local or world space position.
  • Allow three sets of textures on +Y -Y and XZ axis.
  • Diffuse lighting.
  • Specular Lighting.
  • Normal Maps.
  • Emission Maps.
  • Parallax Maps.
  • Opacity Maps for a better texture blending.

Coming next

  • Ambient occlusion.
  • Better normal calculation (currently gradient method on DC meshing).

DevBlog

Feedback
Any feedback or critics will help me greatly. I want this project to be as clear as possible for learning purposes. And i want to know what you would like to see in that kind of projet :

  • Other kind of voxel data structure ? (octree ?)
  • Another meshing algorithm ? (EMC ?)
  • More features for learning purposes ?
  • In editor UI ?

If you have any question about this project or voxel technology don’t hesitate to ask on this thread or contact me. I intend to make some tutorials in french i think there are better english guides than me. Once finished, I will make available this project on the store, the price is not fixed yet, but i would like it to be accessible for most people. I hope you enjoy what you see, and it motivates you to jump in the voxel wagon. :slight_smile:

1 Like

This has a lot of potential! I want to make my own Dual Contouring implementation in Unity as I prefer it a lot to marching cubes as it can produce sharp features where marching cubes cannot, but I do not know where to start. I have searched Google for tutorials but I have found none in C# or Java. How do you get your implementation in Unity/Could you share any resources that would help me implement Dual Contouring into Unity?

You should start with some of the SIGGRAPH papers. I think you should avoid Java as this is an expensive alogrithm and memory can be key. If your are juste starting, first i recommend to implement the Marching cubes algorithm, to understand how it is working. There is many exemple, and DC is juste an improved MC.

One link that helped me a lot, but there are many interesting blog like Voxel Farm or ofps :
http://www.sandboxie.com/misc/isosurf/isosurfaces.html

I hope this post is helpfull, give me some feedback on your project.

Thanks for the quick reply! I didnt realises sandboxie had an atticle on isosurfaces, looks very informative, im going to give it a read. I have implemented Marching Cubes into Unity before but I could never understand dual contouring. I will update you on any progress that I make.

Also I think you should incorporate an octree based LOD into your project

I thought about Octree but it is slower to construct and update than my flat array. My work is not good enough yet, i cant focus on this right now, but i keep it in mind.

Also a better way seems to be the clipmap approach, here some greats post :

http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter02.html

Like the idea of using clipmaps here.

Watching this project fondly. :slight_smile:

When trying the demo you provided I noticed the following things.

  1. I had to refresh the webpage to try a different algorithm

  2. When jumping the character controller behaves perfectly fine, but let’s say you fall off a 100 block structure it will only take you ms-1second to hit the ground. I currently have the same problem with my character controller script. :frowning:

Overall this is wonderful! Keep up the good work!

Amazing! Where did you learn all this if i may ask?

Hello, thank you all for your support. And first Update !

  • Added dynamic chunks managment, tick off “load all chunk…” to try it (Work in progress). Recycle form the chunk pool, display or desable inactive chunks. Especially useful if you are looking for large voxel world.

  • Added “B” hotkey to go back to the world setting screen as advise by Ghosts_Riley.

  • Added a bounding box debuging feature, hit “H” to highlight on/off. You can see isosurfaces boundries and where the scripts are working.

  • Better average fps.

Try this here or in the first post : Voxel World - Update 23/01/15

There is a lot of SIGGRAPH paper on procedural meshing and some very good blog on the subject (see link on my last post). If you have more specific questions i will be glad to answer as best as i can.

I use a simple Physics.gravity for verticale velocity (and inverse for jump). I am not sure how Unity gravity work but you may be looking for a velocity acceleration (as your body take speed while fooling) rather than how i am doing it.

Update 13/02/15.

Triplanar Shader, Normal and Parallax Maps - Update 13/02/15

Today work in progress on my shader :

  • Triplanar shader (in this exemple XZ / +Y / - Y)
  • Texture blending.
  • Normal maps.
  • Parallax maps.

The textures are not the best, and the shader is not optimized yet, but we can see some good results. Tell me what you think, and what you woud like to see.

Good week end :slight_smile:

Yop !
Very amazing work.
I agree that some of the SIGGRAPH paper are really helpfull on the subject.

Very nice work! Does your implemenation support sharp features? I’d love to see an implementation with a working octree - maybe even free for anyone to play with the code? Keep up the nice work!

Thank you for your support !

  • Dual Contouring support sharp features. But it create only one vertex by voxel, so the precision of the mesh depend on the space between two voxels.
  • Octree are very interesting for this kind of data structures, but it may complicated my code so it is not my priority for the moment. Also as said before clipmaps could be better than octree, but i am not sur it is doable in Unity.
  • I am spending a lot of time on that project so i would like to get some return on investment. But if you have any question or need somme help on the subject i can help you as best as my knowledge :slight_smile:

I know i didnt update this post since quite some time, but i don’t like showing work not yet up to some quality.
I will shortly show the news updates regarding multiple materials meshes, better normal calculation for shader and meshing from heightmap.

Hello everyone !

The next update is finaly here :slight_smile:

[Voxel World - Update 09/05/15](http://www.voxelab.fr/build/WebPlayerBuild 0_008.html)

Content :

  • Unity 5.0 upgrade.
  • Heightmap isosurface.
  • Multiple materials, use 1 2 and 3 to switch between them and create new meshes.
  • New normals for Shader (gradient method)
  • New Chunk Manager. The “Load all chunk” option will now load chunks from the player start position to the edge of the World in a spirale kind of way.
  • And lots and lots of debugging…

Known buggs (non exhaustive) :

  • Very big drop frames at chunk creation (due to updating my voxels array). It is the main reason of the delay of this update. I know where it is coming from but i did not manage to completely resolve it yet. However i manage to soften the blow enough so it can be playable. Thus it may brings others buggs on texture and meshing.
  • Normal calculation. I am using the gradient methode of calculation for the shader normals. But as the meshing is not as precise as the densities functions, it creates texture stretching. I am looking at diverses others techniques as weighted normals.
  • The parallax effect of my shader doesnt work properly on procedural mesh according to your view direction.

I hope you enjoy those normals, i think it looks realy nice with parallax :slight_smile:

Hello,

A quick update to solve the frame rate issue:
[Better frame rate - Update 15/05/15](http://www.voxelab.fr/build/WebPlayerBuild 0_009.html)

Hello everyone on this beautiful summer !

Today i would like to start with a little story. This project is my first project on Unity and in C#. For a long time i hesitate to learn and implement multithreading in it. So i spent an enormous amount of time comming with all sort of extravagant ideas to make my chunk manager work faster and faster with coroutines. I learn a lot, but i never reach what i was looking for.
And then i found this ebook :
http://www.albahari.com/threading/

And i say to myself, what a wonderful day. Now let me present to you my project, with multithreading :
Multithreaded voxel world creation

And to show you the change of speed, a 200 x 36 x 200 world creation based on a heightmap (if you looked at previous build, you can see the difference) :

No, not everything is perfect but i am realy pleased with this result.

For those who are looking to do the same, let me explain how i did it.

  • I based my implementation on a consumer/producer queue (you can find an exemple in the book), with a number of worker thread equals to my cpu count -1 (for the main thread).
  • I keep an array of my meshingScripts objects, so each of them has its own memory allocation.
  • And finaly i replace every Unity function (Mathf, vector3, quaternion, etc…) that my meshing scripts was using, so they could be threaded.

And voilà ! (with a lot of debugging).

I have some issue :

  • I use the singleton pattern based on the Unity wiki singleton : http://wiki.unity3d.com/index.php?title=Singleton. But Unity dont like field initialization outside of awake and start function. So some time when i quit the game it raise lots of erors, and i dont know how to avoid it.
  • Marching Cubes was the fastest of the three algorithms (it is a lot of array look up). Now it is the slowest, and i dont know why or how to fix it yet.

My next goal would be to extend my chunk manager to allow boundless world.

I hope you enjoy what you see, and as always if you have any bug report, questions on this project or need help for your own, i am oppen to discussion. :slight_smile:

1 Like

How did you implement the marching cubes approximation? Is there a paper/code for that as well?

The basic Marching cubes approximation is very simple. Its the middle point between two corners , ie : 0.5.

If you are looking toward more advance marching cubes based algorythme like the Extend MC (EMC), you need to intersect the edge more precisly. You do so by iteratively checking the density value of points on the crossed edge (you choose the middle point, between one of the corners and the last point you checked), until you get an acceptable density value (be careful with float to avoid checking for ever).

For Dual Contouring it is a bit more complicated as you take into account mass point, normal directions, and quadratic error function minimization. I cant realy explain it properly and in details here. But, i can show you a good learning site, well explained and with code in C :
http://www.sandboxie.com/misc/isosurf/isosurfaces.html

You also can look at the siggraph papers, which are the most complete sources of informations.

Hello,
In today’s update the last implementation of my chunk manager.
It’s content :

  • Load and unload chunks from the chunk pool.

  • Launch chunks mesh creation if need to be.

  • Faster user’s mesh modification.

  • Boundless world.

  • Meshing priority as follow : user input, chunk in view, and chunk in loading range.

You can see the result here, first part for the DC algorithms, second a look at behind the scene and third Boxel the quickest algorithm, :

And try it here :

Chunk Managment

Coming next I will work on my shader. I am also thinking about starting a more precise dev-blog to share my experiences and hopefully help who wants to learn about voxels.

I hope you enjoy what you see. As always if you have bug reports, questions, or any other discussion related to that kind of project dont hesitate to ask.

Hohoho folks ! Welcome to Buster Friendly’s show and his Friendly Friends !

Today i have some exciting and totally unpublished information for you !
We have sent our expert reporters to inquire about the latest updates on Voxelab and his shaders.
And there is what they found :

Shaders Content

  • 18 Surface shaders based on vertex position and surface’s normal (Triplanar).
  • Based on local or world space position.
  • Allow three sets of textures on +Y -Y and XZ axis.
  • Diffuse lighting.
  • Specular Lighting.
  • Normal Maps.
  • Emission Maps.
  • Parallax Maps.
  • Opacity Maps for a better texture blending.

Try it

Oh my oh my ! What a news !

A special thanks to Nobiax aka Yughues for his amazing and free textures (on cgshare, deviantart, Opengameart and unity store).

To finish on a more serious note.
I would like to imagine what our dear P. K. Dick would have to say after this :
“Do voxels dream of electronic cubes ?”

That’s all folks ! Next on Buster Friendly and his Friendly Friends, the latest version of voxelab with those new shaders.

1 Like