Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 2.32 KB

README.md

File metadata and controls

43 lines (31 loc) · 2.32 KB

This Repository Is Outdated

The new repository is available here, which features faster greedy meshing and a standalone renderer.




voxel-mesh-generation

Optimised voxel mesh generation, written in C# and open sourced from the game Sector's Edge.

Overview

This repository contains C# code for mesh generation on the CPU, setting up VBO and VAOs for OpenGL rendering, as well as fragment and vertex shaders.

The explanation and visualisation of this mesh generation technique can be found in this blog post. Further optimisation details can be found in this blog post.

Mesh generation and VBO buffering is kept separate so that multiple chunks can be initialised on different threads.

Details

  • Chunks are composed of 32x32x32 blocks
  • Faces are generated by combining faces in runs along the X and Y axis.
  • This algorithm produces ~20% more triangles than greedy meshing and runs ~390% faster
  • Block position, texture ID, health and normal are packed into 4 bytes for faster buffering and rendering on the GPU.

Benchmarks

Benchmarks were run with a Ryzen 5 1600 CPU

  • ST = Single Threaded Time
  • MTT = Multithreaded Time - 12 threads each initialising 1/12th of the map
  • CMGT = Chunk Mesh Generation Time
Map Name Chunk Count Total STT (ms) Total MTT (ms) Average CMGT (ms)
Crashed Freighter 799 421 110 0.527
Soltrium Temple 648 280 73 0.432
Aegis Desert 441 201 51 0.456
Magma Chamber 293 157 38 0.535
Arena 108 30 12 0.278

In Practice

With 16 players per match, multiple chunk meshes must be regenerated every frame. This process has been optimised to ensure the game can be played smoothly on older hardware.

Soltrium Temple Screenshot