TechniquesFast rays through big meshes and many instances
Picking and line of sight that stay cheap when the scene is big.
What it costs a frame
- GPU
- 0.72 ms
- CPU, median
- 1.07 ms
- CPU, 95th pct
- 1.79 ms
- Draw calls
- 10
- Weight
- Moderate
Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 0.47–0.72, CPU 0.99–1.46 ms). What ran: Measured with the beacon circling, so all 32 sight lines are recast through the grids every frame (plus a few lines a frame recast each quick way in turn, and one through three’s own every 1.5 s), and a pick through the middle of the screen each frame. 4,000 stones, 40 walls and 20,000 terrain triangles. Phones: tiers are being measured next.
| Machine | GPU ms | CPU ms | CPU p95 |
|---|---|---|---|
| RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool | 0.72 | 1.07 | 1.79 |
| apple · Apple A19 Proin a browser tab · 16 November 2026 | 6.47 | 2.60 | 3.32 |
| Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026 | 4.33 | 2.73 | 3.44 |
Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.
What it needs
- Renders with
- WebGPU or WebGLWebGPU where there is one, WebGL2 where there is not.
- Your browser
- Runs hereNo WebGPU needed
- Depends on
- three.js 0.187.0No other packages
What it’s for
- Picking among thousands of instanced props, trees or stones
- Line of sight for many agents a frame (NPCs, cameras, creatures that look around)
- Rays against a big terrain or a merged town of walls
- Hover highlights in a large 3D scene without frame drops
- Placing things on the ground under the pointer
- Sound or light occlusion tests between many points
Pitfalls, in brief
- The mesh grid is over the mesh’s own x and z.
- Static geometry only: the grid is built once from the positions.
- The instance spheres are rebuilt only when
version()changes. - Hits come back in the order the cells were walked, not sorted:
Raycaster.intersectObjectsorts them, but a caller ofmesh.raycastdirectly must sort them itself. firstHitOnlyis a property you add to the Raycaster (as three-mesh-bvh does).
5 more in brief
- A cell that holds most of the mesh (a few huge triangles over the whole ground, a spire with thousands of triangles in one cell) is no faster than three.
- An array of materials, or a draw range that leaves part of the geometry out, falls back to three’s test (one material over several geometry groups is fine: three tests every triangle then too).
- Tall vertical faces stack in one cell: the grid is two-dimensional, so a wall of many rows of triangles puts them all in the cells along its foot.
- An instance scaled to zero is never hit (its sphere has no radius): that is how the source hides placed props.
- The model grid for an instanced batch (
gridFrom, 300 triangles) is in the model’s own units: a 1 m stone with the default 2 m cell is one cell and pure overhead.
Where it comes from
From HaTac. Fully custom code.
Amanatides and Woo, A Fast Voxel Traversal Algorithm for Ray Tracing (1987): The grid walk (a DDA stepping to whichever cell boundary is nearer), here in two dimensions. The algorithm, not code.
three-mesh-bvh (Garrett Johnson): The `raycaster.firstHitOnly` convention is borrowed so callers written for it work here. No code.
Jarzynski and Olano, Hash Functions for GPU Rendering (2020): The PCG hash the demo scatters its stones with.


