Three.js Level of Detail (THREE.LOD Performance)
Level-of-detail rendering in Three.js with 600 procedural asteroids, each a THREE.LOD with 20k / 1.3k / 80-triangle meshes, with colour-coded levels, distance and hysteresis tuning and live triangle and draw-call counts.
Key topics: three.js lod, level of detail, performance, triangle count, optimization, renderer info
Game Over
What this code does
- THREE.LOD: each object holds several meshes and shows the one whose distance threshold matches its distance from the camera.
- Automatic Updates: the renderer calls `lod.update(camera)` every frame, so no manual bookkeeping is needed.
- Hysteresis: a margin around each threshold stops objects flickering between levels at the boundary.
- Measuring: `renderer.info` (with autoReset off) reports triangles and draw calls per frame; toggle LOD to see millions of triangles drop.
- Colour Coding: green, yellow and red show which detail level each asteroid is using as the camera flies.
- Controls: LOD on/off, mid and low detail distances, hysteresis, level colours and camera flight.
Related Demos
Continue Learning
JavaScript Implementation
const lod = new THREE.LOD()
lod.addLevel(new THREE.Mesh(new THREE.IcosahedronGeometry(1, 30), material), 0) // close: 20k tris
lod.addLevel(new THREE.Mesh(new THREE.IcosahedronGeometry(1, 7), material), 18) // beyond 18 units
lod.addLevel(new THREE.Mesh(new THREE.IcosahedronGeometry(1, 1), material), 45) // beyond 45 units: 80 tris
scene.add(lod) // the renderer calls lod.update(camera) automatically (lod.autoUpdate = true)
renderer.info.autoReset = false
function animate () {
requestAnimationFrame(animate)
renderer.info.reset()
renderer.render(scene, camera)
console.log(renderer.info.render.triangles) // compare with LOD disabled
}
animate()