Console tool that bakes opacity micromaps (OMM) for glTF files and stores them using the proposed
EXT_mesh_opacity_micromap
extension.
For every triangle primitive whose material uses alphaMode MASK or BLEND with a
baseColor texture, the tool classifies the alpha content of each (subdivided) triangle into
opaque / transparent / unknown micro-triangle states and writes the packed micromap data,
triangle records, usage histograms and per-triangle micromap indices into the glTF.
The on-disk data is layout-compatible with the build inputs of Vulkan VK_KHR_opacity_micromap
and DirectX 12 opacity micromaps.
- Lossless output: the original JSON document is patched (nlohmann json), never
regenerated — all extensions and structure are preserved verbatim. Supports
.gltfand.glb. - Separate binary file: all micromap data goes into a new
<output>.omm.binbuffer, existing buffers/bin files are untouched and referenced as-is. - Micromap dedup across meshes: primitives that are identical by content (same decoded UVs/indices, same texture and bake parameters) share a single micromap object.
- Large-scene streaming: glTF buffers are memory-mapped,
EXT_meshopt_compressionaccessors are decompressed on demand, and textures are decoded lazily from within the parallel bake jobs and freed as soon as their last job finishes. - Two bake backends:
- NVIDIA OMM SDK CPU baker (default, fetched automatically at CMAKE configure time)
- meshoptimizer's experimental opacity micromap generator
(
meshopt_opacityMap*, always available)
- Textures: KTX1/KTX2 (incl. Zstd supercompression) via nvpro_core2's nv_ktx, DDS (DX9/DX10 headers) via nv_dds, BC1/2/3/7 block formats via bcdec, PNG/JPG/TGA/BMP via stb_image.
We recommend the use of vk_gltf_renderer to test the generated content.
In this image, the use of the any-hit shader is visualized through yellow surfaces. The left tree shows a drastic reduction in any-hit shader invocations as a result of using OMMs.
Requires CMake 3.22+, a C++20 compiler and nvpro_core2 (found next to the project or cloned automatically).
cmake -S . -B build
cmake --build build --config Release
The configure step (cmake -S . -B build) needs network access and git: on first
run it clones nvpro_core2 (unless a copy is found next to the project) and, with
USE_OMM_SDK=ON, the OMM SDK and its submodules into build/_deps/; nvpro_core2
pulls in its own third-party libraries as part of this. Re-configuring reuses the
existing checkouts.
Options:
| CMake option | default | |
|---|---|---|
USE_OMM_SDK |
ON |
build the NVIDIA OMM SDK CPU bake backend |
OMM_SDK_ROOT_OVERRIDE |
path to an existing OMM SDK checkout (skips the git clone) | |
OMM_SDK_GIT_TAG |
v1.9.2 |
OMM SDK version to fetch |
gltf_omm_baker <input.gltf|glb> [options]
--output, -o <path> output file (default: <input>_omm.<ext>)
--mask 0|1 bake alphaMode MASK materials (default 1)
--blend 0|1 bake alphaMode BLEND materials, always 4-state (default 1)
--alphacutoff <f> override material alphaCutoff, < 0 = per-material (default)
--format 2|4 2-state or 4-state micromaps (default 4)
--maxsubdivlevel <n> maximum subdivision level 0..12 (default 8)
--subdivscale <f> approx. microtriangle size in texels (default 2.0)
--threads <n> worker threads, 0 = hardware concurrency (default)
--backend <b> auto | omm | fallback (default auto)
--force rebake primitives that already carry the extension
--stats verbose per-job statistics
The tool writes <output>.gltf/.glb plus <output>.omm.bin next to it. Relative
buffer/texture URIs are preserved, so the output should be written to the same directory
as the input (or the referenced files must be reachable from the output location).
Example:
gltf_omm_baker scene.gltf -o scene_omm.gltf --stats
- The effective alpha cutoff folds
baseColorFactor.ainto the material'salphaCutoff;KHR_texture_transformon the baseColor texture is applied to the UVs before baking. - Primitives whose triangles all end up in the same uniform special state (fully opaque/transparent) are skipped — a micromap would add no information.
- The fallback backend approximates non-REPEAT sampler wrap modes as REPEAT and handles non-0.5 cutoffs by remapping the alpha plane; the OMM SDK backend is authoritative.
- The extension is added to
extensionsUsedonly (notextensionsRequired) — consumers without micromap support can fall back to regular alpha testing. - The code for this project was mostly generated through AI coding tools.
Apache-2.0 (see source headers). Vendored third-party code:
cgltf (MIT, with a local EXT_mesh_opacity_micromap read patch),
bcdec (MIT/Unlicense).
