- Home /
how does the greedy meshing algorithm work?
i have read about the greedy meshing algorithm in various places and from what i managed to understand it is an algorithm for voxel engines that is ment to minimize the amount of quads rendered? i didn't really get my hand around it because the site that everyone is referring to (this site) uses javascript for the example (i think it's javascript anyway, i use C#). could someone please explain how it works?
JavaScript isn't too different from C# when it comes to actual code inside functions.
Anyway, the way it works is that for any cell, the algorithm tries to find the largest possible plane that encompasses the surrounding cell faces of the same type (top, left, right etc.) and create one big face out of it ins$$anonymous$$d of having one small face per cell. Some algorithms only go in horizontal or vertical lines. The greedy mesh procedure has one primary advantage: The number of vertices can be kept to a $$anonymous$$imum. The flatter the terrain is, the more pronounced this advantage is. Less vertices means that chunks can be bigger since they are less likely that their meshes break the 65k vertices limit, and also the thing that commonly takes the most times and resources while generating a mesh is applying the collision mesh, so if that mesh is kept simple, it is being applied faster. The disadvantage is that the greedy algorithm itself takes resources, but that's commonly far outweighed by the benefits.