# What does mean the float value in a voxel data?

We know that a voxel can be represented by a three dimensional array of boolean or float values. There is an answer that demonstrates this perfectly: the difference between binary/boolean or floating-point voxel.

If we use the binary way, we probably use a byte[,,], so we have 256 slots. They can be used to represent the content. For example, 0 can be air, 1 grass, 2 stone, 3 water.

By this way, we can define what is solid or not and which colour where.

But what about the floating-point way? So my question: What does the float value mean in a floating-point voxel context? Is there a way to use it as the binary way to describe the content and keep the terrain smooth?.

## What I've experimented & What I get it?

I've tried to build a mesh with Marching Cube, filled with "random" 3d fractal from Perlin Noise. The result looks very good, but now how I am supposed to define what is what? (Air, Stone, ...)

I understand there is a threshold which defines what is solid or not.

Giving me 3 for-loop pseudo code to fill with floating-point the three dimensional array would probably be helpful.

You are actually confusing a few values.. Basically a Voxel is just a point in space followed by how 'full' that space is. If you are using a boolean system then its either full or empty. Minecraft is a common example of this, though the data has started becoming more complicated, they used an integer value of 0 to mean the space was completely empty while a number greater than 0 meant it was full as well as being the material id used to render that block.

For float values in a voxel situation its still generally tracking the same data, just how much of the voxel is 'solid'. This value would then be used in conjunction with the ones around it to translate it from voxel data to mesh data for rendering. For example say we have a voxel that has a value of 0.5 (I am going to assume 0.0 is empty and 1.0 is a completely full location). This would give us a block (if you are rendering cubes) that would be half full. Now when you use this value in association with the other values around it you would get a slope up or down to each location around it depending on if their value is higher or lower.

Note however that I have said nothing about what type of material or texture this block uses. If you are using floats you generally are going to be looking for slopped and smooth meshes to come out of them and another value, maybe an integer still, that actually links to the texture information. The down side to voxels is they take up a lot of space and their translation can be taxing on a computer when they are changed and need to regenerate the mesh. Games like Minecraft, Terraria, and I presume (though have never seen their code) Trove and Creativerse take a shortcut and put both the density and material values into the same data slot to preserve space and lookup times, when you find a block that isn't empty you already have the material Id for example.

Hope this clears up what you were looking for.

• how 'full' that space is. God, thank you for answering me ! Now I understand the meaning of the float value :D. About the texturing, I guess you're right, I need a second value for each point. I've experimented and It's work, by adding a class who wraps the float value and a "blockType". – Alaanor Sep 8 '16 at 8:48
• Glad I could help. – James Sep 8 '16 at 18:00

Marching Cube is a so called isosurface extraction algorithm.

That is (in this case) an algorithm which creates a 3D mesh based on where the voxel values change from positive to negative, i.e. where they are 0.

The floating point values are exactly that, they're used by marching cubes to determine where to place the mesh. Marching cubes has no concept of material types, it only cares about whether or not something is at the sample points.

What you want to do is one of two things:

If you want every triangle to be of only one material, loop through the triangles created and:

• Calculate the voxel positions of each vertex (i.e. round their positions assuming no scaling)
• Retrieve what material each vertex is made of, you know what voxel they are in, those voxels also have a material that marching cubes doesn't know about.
• Set the triangle's material to the material most often encountered (with some edge cases where three materials meet)

If you want the triangles to smoothly interpolate between materials you're gonna need to do pretty much the same thing but set different data for each vertex in some complicated method depending on how you are rendering things.

• Good explanation, unfortunately for me, I didn't learned anything from your answer. Maybe I didn't ask very well my question. I would like to define a "wave" of stone, then grass and air. Exactly like in this tutorial: Unity voxel tutorial part 6 (On the triple for-loop code). But it's work because he use the binary way. How to do the same in floating point way ? – Alaanor Sep 6 '16 at 11:51
• If you want cubes do what he did, if you want marching cubes and smooth terrain do what I wrote above. Have both a density and a material data source. Marching cubes doesn't know what a material is, the extensions suggested above allow it to emit material data. – Elva Sep 6 '16 at 13:12