Rounding edges of cubes (Voxels and Marching Cubes)

Hello,

Over the passed few weeks I have been playing around with a voxel based engine as a pet project. More of a learning exercise. I recently discovered marching cubes and how interesting the algorithm is!

Long-story short, I do not quite understand the marching cube algorithm enough to modify it to reproduce this effect: Unity Destructible Voxel Terrain -- Very Early Stages -- - YouTube

I am using binary voxel data, so my implementation gives this effect: - YouTube

Please note neither of those videos are my own!

Would anyone please be able to enlighten me?

Thanks!

Well, first of all, I think your text above links movies in the wrong order. I think you want to get the effect you see in the russian video, but you text says you have that effect and want the other one.


Anyway… the effect you see in the russian video isn’t vanilla marching cubes. One can clearly see that they get arbitrary angles, which marching cubes can’t do. Marching cubes look like this:

As you see, only certain angles are generated

Now, if what this is about is the effect that you apply some effect to the voxel field and you get kind of a melting away effect, where the material is pushed away slowly, this can be achieved, but every single angle on the small voxel cubes will still be kind of blocky like in the picture I showed.

First:
Don’t use binary voxels… don’t just store 0 for air or 1 for solid… store a float between 0 and 1 and have a threshold value - 0.5 for starters - to interpret the voxel as air or solid.

This threshold value can also be animated by the way, which gives nice effects. Raise it, to only show denser material or lower it, to also show less dense material.

For this to be visible at all, you need a good a good scalar field to play with - something that does not only have 0 or 1, but values in between and it needs to be somewhat coherent when you move through it.

So grab your favorite 3D noise function and initialize your scalar field - the unity Perlin noise isn’t good enough, because it’s only 2D.

I recommend this for a simple single-file drop-in solution:

http://code.google.com/p/simplexnoise/source/browse/trunk/SimplexNoise/Noise.cs

But watch out - this returns values between 1 and -1, so scale it accordingly to get [0…1]

Now - the above should be no problem for you, you only have to change your code where you check for voxelvalue==1 to check for voxelvalue>threshold

Once you have the above, make the threshold changeable on the fly and see how the mesh gets recreated. On the fly is important here… you want to see it in the same scalar field, not a new one after you restart with a new threshold.

If you got that far, now the melting effect can be achieved by not setting the values directly in the scalar field when you click with your mouse, but use subtractive smooth brushes - e.g. define a brush with a radius of 6 and a falloff of the brush value from 1 in the middle to 0 at distance=6 from the middle point.

Now if you click somewhere, you subtract the brush value for every voxel it overlaps. You can multiply the brush value with 0.05 or something like that, if it’S to fast to see.

Now with this brush, your density values will slowly melt away till they fall below the threshold and pop out of existance.