meshoptimizer mesh optimization
An MIT library that reorders for vertex cache and fetch efficiency, simplifies meshes for LOD, builds meshlets, and encodes vertex and index buffers for fast decoding.
Also known as meshopt, EXT_meshopt_compression
In the family Performance, LOD & compression, mesh optimization
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { createMeshlets } from 'three/addons/utils/MeshletGeometryUtils.js' (uses MeshoptClusterizer, MeshoptSimplifier) docs Official addons consume meshoptimizer; no general mesh-optimize pass. |
| Babylon.js 9.38.0 | Official add-on | glTF EXT_meshopt_compression loader extension (MeshoptCompression) docs |
| Godot 4.7 | Built in | ImporterMesh.generate_lods(); scene import option Meshes > Generate LODs docs Godot bundles meshoptimizer for LOD generation. |
| Unity | Official add-on | Package Manager > Meshopt Decompression (com.unity.meshopt.decompress) docs Decoder for meshopt-compressed glTF meshes (EXT_meshopt_compression). |
| Unreal 5.7 | None found | |
| Blender 5.2 | Official add-on | File > Export > glTF 2.0 > Data > Compression (Meshopt) docs Bundled glTF 2.0 add-on writes EXT/KHR_meshopt_compression. |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Index buffers are reordered for post-transform cache hits, then vertices are reordered for fetch locality, and overdraw can be reduced further. Simplification collapses edges with a quadric error metric, returning a measured error that picks LOD by screen size. Buffer codecs byte-transposes and delta-codes streams so a general-purpose compressor works well, and the decoder runs at gigabytes per second using SIMD or WebAssembly.
The same library builds meshlets with bounds and cones for cluster pipelines.
When to choose it
Reach for it when
- scene has too many triangles for the gpu
- mesh loading and vertex fetch is slow
- reduce model size for web delivery
- need lod versions of meshes automatically
Choose it as the default post-process for any mesh shipped to a GPU, and for LOD chains and meshlets. Prefer Draco mesh compression when size is the only goal and decode speed is irrelevant. Prefer Nanite virtualized geometry when the engine builds cluster hierarchies itself.
Field marks
- Aggressive simplification collapses thin features and breaks UV seams
- Attribute errors are not captured unless weighted
- Decoding requires matching filter and mode settings per stream
- Lossy quantization visible at large object scales
Presets
meshoptimizer meshlet limits
{
"max_vertices": 64,
"max_triangles": 126,
"cone_weight": 0.25
}Attribution: Defaults from the meshoptimizer README (MIT license). · basis: 0
meshoptimizer — 64-triangle meshlet clusters & QEM LOD wireframe (left) vs vertex-cache-optimized smooth shading (right)
{
"P_MESHLET_RES": 7,
"P_LOD_ERROR": 0.55,
"P_WIREFRAME": 0.45,
"P_SPLIT": 0.48
}Show GLSL (132 lines)
const float P_MESHLET_RES = 7.00; // P Meshlet Density [4.0, 12.0, 1.0]
const float P_LOD_ERROR = 0.55; // P QEM LOD Step [0.0, 1.0, 0.05]
const float P_WIREFRAME = 0.45; // P Triangle Wire [0.0, 1.0, 0.05]
const float P_SPLIT = 0.48; // P Meshlets / Shaded [0.0, 1.0, 0.02]
float hash31(vec3 p) {
p = fract(p * 0.1031);
p += dot(p, p.yzx + 33.33);
return fract((p.x + p.y) * p.z);
}
vec2 rot2(vec2 p, float a) {
float c = cos(a);
float s = sin(a);
return vec2(c * p.x - s * p.y, s * p.x + c * p.y);
}
// Sculpted twisted torus-shell geometry ideal for showcasing spatial meshlet partitioning & LOD
float mapMesh(vec3 p, float t) {
p.xz = rot2(p.xz, t * 0.48);
p.xy = rot2(p.xy, 0.30);
vec2 q = vec2(length(p.xz) - 0.38, p.y);
float ang = atan(p.z, p.x);
q = rot2(q, ang * 1.5);
float dBox = length(max(abs(q) - vec2(0.11, 0.16), 0.0)) - 0.055;
return dBox * 0.82;
}
vec3 calcNormal(vec3 p, float t) {
vec2 e = vec2(0.0025, 0.0);
return normalize(vec3(
mapMesh(p + e.xyy, t) - mapMesh(p - e.xyy, t),
mapMesh(p + e.yxy, t) - mapMesh(p - e.yxy, t),
mapMesh(p + e.yyx, t) - mapMesh(p - e.yyx, t)
));
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
float mRes = clamp(P_MESHLET_RES, 3.0, 14.0);
float lodErr = clamp(P_LOD_ERROR, 0.0, 1.0);
float wireAmt = clamp(P_WIREFRAME, 0.0, 1.0);
vec3 ro = vec3(0.0, 0.28, 2.08);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.07, -1.50));
vec3 lDir = normalize(vec3(0.58, 0.78, 0.52));
vec3 col = mix(vec3(0.05, 0.07, 0.12), vec3(0.13, 0.18, 0.28), smoothstep(-0.4, 0.5, uv.y));
float tRay = 0.05;
bool hit = false;
for (int i = 0; i < 64; i++) {
float h = mapMesh(ro + rd * tRay, iTime);
if (h < 0.002) { hit = true; break; }
tRay += h;
if (tRay > 6.0) break;
}
if (hit) {
vec3 p = ro + rd * tRay;
vec3 n = calcNormal(p, iTime);
// Transform hit to rigid object space for stable meshlet IDs
vec3 pObj = p;
pObj.xz = rot2(pObj.xz, iTime * 0.48);
pObj.xy = rot2(pObj.xy, 0.30);
float ndl = max(dot(n, lDir), 0.0);
float spec = pow(max(dot(reflect(-lDir, n), -rd), 0.0), 42.0);
float fres = pow(1.0 - max(dot(n, -rd), 0.0), 4.0);
if (screenX < split) {
// Left: Voronoi-like 3D spatial meshlet clusters (each cluster ~64 tris) + QEM triangle density grid
vec3 scaled = pObj * mRes;
vec3 cid = floor(scaled);
float bestD = 9.0;
float secondD = 9.0;
vec3 bestId = cid;
for (int dz = -1; dz <= 1; dz++) {
for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
vec3 nb = cid + vec3(float(dx), float(dy), float(dz));
vec3 jit = vec3(hash31(nb), hash31(nb + 13.7), hash31(nb + 29.1));
float dd = length((nb + jit * 0.75 + 0.125) - scaled);
if (dd < bestD) {
secondD = bestD;
bestD = dd;
bestId = nb;
} else if (dd < secondD) {
secondD = dd;
}
}
}
}
float hId = hash31(bestId + 5.3);
vec3 meshletCol = 0.50 + 0.44 * cos(vec3(0.0, 2.05, 4.10) + hId * 6.2831853);
float clusterBorder = smoothstep(0.08, 0.015, secondD - bestD);
// Sub-cluster QEM simplified triangle wireframe
float triFreq = mix(28.0, 10.0, lodErr);
vec3 tf = fract(pObj * triFreq);
float triEdge = min(min(min(tf.x, 1.0 - tf.x), min(tf.y, 1.0 - tf.y)), abs(tf.x + tf.y - 1.0));
float wire = smoothstep(0.08, 0.015, triEdge);
col = meshletCol * (0.28 + 0.88 * ndl) + vec3(0.95) * spec * 0.35;
col = mix(col, vec3(0.06, 0.08, 0.12), wire * wireAmt * 0.55);
col = mix(col, vec3(0.98, 0.98, 1.0), clusterBorder * 0.65);
} else {
// Right: Vertex-cache & overdraw-optimized clean shaded metallic ceramic surface
vec3 alb = mix(vec3(0.76, 0.79, 0.84), vec3(0.92, 0.66, 0.34), 0.5 + 0.5 * n.x);
col = alb * (0.22 + 0.94 * ndl) + vec3(1.15, 1.08, 0.98) * spec * 0.90 + vec3(0.32, 0.66, 0.98) * fres * 0.55;
}
} else if (rd.y < -0.005) {
float tf = (-0.54 - ro.y) / rd.y;
if (tf > 0.05 && tf < 14.0) {
vec3 fp = ro + rd * tf;
float sh = smoothstep(0.28, 0.72, length(fp.xz));
vec2 g = abs(fract(fp.xz * 2.5) - 0.5);
float grid = smoothstep(0.04, 0.01, min(g.x, g.y));
col = mix(col, mix(vec3(0.10, 0.12, 0.17), vec3(0.24, 0.30, 0.42), grid) * (0.35 + 0.65 * sh), exp(-tf * 0.16));
}
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.98, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| meshoptimizer-live | Tesla T4 1920x1080 | 20.0× baseline (heavy) · 0.658 ms / 0.683 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| meshoptimizer-live | NVIDIA L4 1920x1080 | 18.2× baseline (moderate) · 0.289 ms / 0.292 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| meshoptimizer-live | NVIDIA A100-SXM4-40GB 1920x1080 | 13.7× baseline (moderate) · 0.395 ms / 0.400 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Meshlets (cluster rendering): meshopt builds clusters and orders their indices for mesh shaders.
Sources
- primaryzeux (2016). zeux/meshoptimizer. Mesh optimization library that makes meshes smaller and faster to renderGitHub API · license MIT · 2026-11-29