Skip to content

PRIArobotics/binary-greedy-meshing-py

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binary Greedy Meshing

Fast voxel meshing algorithm - creates 'greedy' meshes with support for voxel types, baked light & Ambient Occlusion. UVs can easily be added but the vertex structure would have to be changed from a single integer.

Setup example (Visual Studio)

> git clone https://github.com/cgerikj/binary-greedy-meshing --recursive
> cd binary-greedy-meshing
> mkdir build && cd build
> cmake .. -G "Visual Studio 16 2019"
> start binaryMesher.sln

Program usage

  • Noclip: WASD
  • Toggle wireframe: X
  • Regenerate: Spacebar
  • Cycle mesh type: Tab

Meshing duration is printed to the console.

Algorithm usage

The mesher lives in src/mesher.h

Input data:

  • std::vector<uint8_t> voxels (values 0-31 usable)
  • std::vector<uint8_t> light (values 0-15 usable)

The input data includes duplicate edge data from neighboring chunks which is used for visibility culling and AO. Input data is ordered in YXZ and is 64^3 which results in a 62^3 mesh.

Output data:

  • std::vector<uint32_t> of vertices in chunk-space.

Mesh details

Vertex data is packed into one unsigned integer:

  • x, y, z: 6 bit each (0-63)
  • Type: 5 bit (0-31)
  • Light: 4 bit (0-15)
  • Normal: 3 bit (0-5)
  • AO: 2 bit

Meshes can be offset to world space using a per-draw uniform or by packing xyz in gl_BaseInstance if rendering with glMultiDrawArraysIndirect.

Screenshots

Mesh Wireframe

Benchmarks

Average execution time running on Ryzen 3800x.

Scene Milliseconds Vertices
3d hills 1.139 46798
Red sphere 1.108 71532
White noise 33.315 2142608
3d checkerboard 36.832 4289904
Empty 0.174 0

Releases

No releases published

Packages

No packages published

Languages

  • C 90.0%
  • C++ 9.0%
  • Other 1.0%