Marching cubes, voxels, few suggestions needed

I am trying to build proper destructible terrain, for research purposes only. Well, everything went well, but the resolution does not satisfy me. I have seen many examples of how people implement the MC algorithm, but most of them, as I understand it, use functions to triangulate a finite mesh, which is not suitable for me.

I will try to briefly explain how I build my terrain, and perhaps one of you will give me advice on how to improve or increase the resolution of the final terrain.

1) Preliminary calculation of the triangular nicks MC.

I start a simple cycle through the MC search tables for each case (0-255) and compute the triangular angry rage: [0,0,0] - [1,1,1]. There are no problems.

2) Landscape

I have a terrain class that stores my voxels. In general, it looks like this:

int size = 32;//Size of each axis. unsigned char *voxels = new unsigned char[(size * size * size)/8]; 

So, each axis has a length of 32 units, but I store voxel information per bit. This means that if the bit is on (1), there is something, and something needs to be drawn.

I have a couple of functions:

 TurnOn(x,y,z); TurnOff(x,y,z); 

to enable or disable voxel location. (Helps to work with bits).

After highlighting the terrain, I start the perlin noise and turn the bits on or off.

My terrain class has another function - to extract the Marching Dice case number (0-255) from location x, y, z:

 unsigned char GetCaseNumber(x,y,z); 

by determining whether the neighbors of this voxel are on or off. There are no problems.

3) Part rendering

I loop for each axis, extract the case number, then get the pre-calculated triangular nicks, translate into x, y, z coordinates and draw these triangular nicks. There are no problems.

So, the result looks like this:

terrain

But, as you can see, in any place the resolution is not comparable, for example, with this: MC
(source: angelfire.com )

I saw in MC examples that people use what is called “out of meaning”, which I don’t understand. Any suggestions on how to improve my work, or what are the ISO values, and how to implement it in a single grid, would be really good.

+8
source share
1 answer

The problem is that your voxels are a binary mask (on or off).

This works great for the default marching cubes algorithm, but that means you get sharp edges in your grid.

A smooth example is probably generated from smooth scalar data.

Imagine if your data changes smoothly between 0 and 1.0, you set the threshold to 0.5. Now, after you determine what configuration the given cube has, you look at all the vertices created.

Say you have a vertex on the edge between two voxels, one with a value of 0.4, and the other 0.7. Then you move the vertex to a position where you get exactly 0.5 (threshold) when interpolating between 0.4 and 0.7. Thus, it will be closer to the peak of 0.4.

This way, each vertex is exactly on the basis of the interpolated iso surface, and you will create much smoother triangles.

But this requires your input voxels to be scalar (and change smoothly). If your voxels are two-level (all either 0 or 1), this will result in the same triangles as before.

Another idea (not the answer to your question, but perhaps useful):

To achieve a smoother rendering, without mathematical correctness, it would be advisable to calculate the average normal vector for each vertex and use this normal for each triangle connecting to it. This will hide the sharp edges.

+9
source

All Articles