Improve 3D model rendering speed and reduce file size
If models in games or 3D apps are slow or files are large, you can address this by adjusting how the GPU processes data. This library provides algorithms to reorder and compress mesh data, improving rendering efficiency. It supports C and C++ interfaces and can also be used in Rust or JavaScript.
Reordering data for each stage of the rendering pipeline
It changes the order of vertex and index data so the GPU can process triangles efficiently. Vertex cache optimization adjusts triangle order to reduce vertex shader executions, while overdraw optimization minimizes overlapping pixels. Vertex fetch optimization improves memory access patterns, and quantization converts vertex data into smaller formats to save storage space. The recommended process starts with indexing, followed by quantization, and then index filtering. Each step improves processing speed and memory usage without affecting the visual result of the mesh.
Clustering for mesh shaders
Recent GPU architectures enable more flexible geometry processing through mesh shaders. This library provides an algorithm to divide meshes into small units called meshlets. Meshlets contain vertex and index buffers, which is advantageous for culling, allowing clusters not visible on screen to be removed quickly. The meshopt_buildMeshlets function balances vertex reuse efficiency and culling efficiency to generate data suitable for the GPU. Generated meshlets can be optimized individually, and bounding volume information can be calculated for runtime culling.
Installation and build methods
The library consists of C++ source files and C-compatible header files. You can build it using CMake or add only the source files for the required algorithms to your project. It can also be installed via Linux distribution packages (Debian, Ubuntu, etc.), Vcpkg, or Conan. gltfpack, a command-line tool that automatically optimizes glTF files, is available as a binary download from the release page or as an npm package. Rust users can access some algorithms via the meshopt crate, and JavaScript users via meshoptimizer.js.
Considerations before applying
This tool is most effective for static meshes or meshes with few deformations. Overdraw optimization may offer no benefit on mobile GPUs using tile-based deferred rendering, so performance measurement is required before application. Mesh shader features are supported on GPUs such as Turing, RDNA2, Arc, and M3/A17 Pro or higher. Quantization may reduce the precision of vertex data, so you must select a quantization format that meets the model's quality requirements. The library is distributed under the MIT license, and on platforms with specific hardware limitations, you may need to define the MESHOPTIMIZER_CLUSTERIZER_INDEXLIMIT macro to build it.