#greedy mesh for voxel world

1 messages · Page 1 of 1 (latest)

crystal monolith
#

Hi guys. I'm creating a voxel world and.k have implemented this algorithm https://forum.unity.com/threads/after-playing-minecraft.63149/page-49 to reduce the number of vertices.
The algorithm works but It creates some unnecessary faces that are facing inside the cube as you can see in the picture

Is there an easy way to remove this face or do I need to edit the algorithm code?
Outside the cube looks fine, the problem is that I have some faces inside that are not needed.

void elk
#

It it not easy to understand what algorithm you are talking about reading this page.
But clearly, unless you are using a shader that doesn't do face culling (default standard shader does regular backface culling), those additional faces are generated from you code and should just be filtered out to not be included in the mesh.

crystal monolith
#

The cube from my screen is made by 16x16x16 little cubes. The algorithm reduces the number of vertices "merging" near block faces.

#

I know that the wrong faces are generated by my code but I wonder if a can remove them easily

void elk
#

You could check for faces that point "inward" and remove them ?
But the best would be to just not generate them to begin with, so need to rework the code.

ruby palm
#

The direction of a face is determined by its "Winding Order" - https://docs.unity3d.com/Manual/AnatomyofaMesh.html

The order of the vertices in each group in the index array is called the winding order. Unity uses winding order to determine whether a face is front-facing or back-facing, and in turn whether it should render a face or cull it (exclude it from rendering). By default, Unity renders front-facing polygons and culls back-facing polygons. Unity uses a clockwise winding order, which means that Unity considers any face where the indices connect in a clockwise direction is front facing

https://docs.unity3d.com/uploads/Main/mesh-winding-order.png

So if you're going to edit the algorithm, check for any extra faces being set with the backwards winding order. This would be done when setting a meshes "Triangles" or "Indices" array.

And like Remy said, make sure you're not just using a material that is set to render both sides :)

crystal monolith
#

I don't think the material is causing the problem because only 2 inside faces are visible. The final mesh has 32 vertices instead of 24 ( 4 vertex per for every face). I'm pretty sure there is a problem in the algorithm. I wonder if there is a way to find those vertices and remove them without editing the algorithm

ruby palm
#

I think you would have to edit the original algorithm. To know what faces are pointing the wrong way, you would have to know the desired shape of the object, which would require basically implementing the original algorithm