cesium: Globe picking is very slow
The current approach for globe picking is intersect the ray against all rendered tiles (using their bounding spheres) and sort the intersected tiles by closeness to ray. Then, for the closest tile do ray-triangle intersection tests against all of its triangles and return the closest. If there was none, test the next tile. And repeat.
This could be optimized some more. ScreenSpaceCameraController
does one or two globe picks per frame and that alone can slow down Cesium severely with detailed terrain providers like ArcGIS
.
Some ideas on how to improve this:
- Custom intersection test for heightmap providers since we know their triangles are on a grid
- Per-tile octree for non-heightmap providers (too slow to generate?)
- Remove
TerrainEncoding
quantization for faster position decode from vertex buffer (only affects nearby tiles) - Cache recently used triangles in a form that makes future picks faster, maybe by pre-calculating some of the math from
IntersectionTests.rayTriangleParametric
. - Unroll picking math
Sandcastle (console prints how long each pick takes with left click). Select ArcGIS
from the dropdown for some seriously slow speeds.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 19 (13 by maintainers)
Those two optimization ideas are good. I agree with the plan to optimize the JS version first, and then convert to WebAssembly if necessary. And yeah, draco is the only one so far. So then it’s a matter of deciding what programming language to use, etc, etc and may involve input from other team members. So that’s more for the distant future, even though I think it could speed things up a decent amount.
I’d like to avoid calling
triangleVerticesCallback
for every triangle by instead passing a vertex grid directly to a new function calledaddTrianglesFromHeightmap
. CurrentlytriangleVerticesCallback
insideHeightmapTessellator
figures out the vertex index from the triangle index, but it’s not very optimized.I’m in the same situation as you, only able to work on this in my spare time. I want to get back to this in around 2-3 weeks, but even then I’m not positive. I’ll give an update then.
This actually came up twice this week on the forum: