potential bugfix/overscaled 3d tile raycast#13618
potential bugfix/overscaled 3d tile raycast#13618dwayneparton wants to merge 2 commits intomapbox:mainfrom
Conversation
|
Hey, @dwayneparton 👋 Thanks for your contribution to Mapbox GL JS! Important: This repository does not accept direct merges. All changes go through our internal review process. What happens next:
Please respond to any review comments on this PR. For more details, see CONTRIBUTING.md. |
|
Hi @dwayneparton, thank you for the PR and contribution. I have tested this code and it does work really nicely. My main concern is performance - did you have any findings in your rudimentary benchmark tests? I'm seeing about a 5-30x increase, just wondering if you noticed the same. |
2026-02-10.09-58-27.movI'm definitely seeing a difference. It seems to vary between both raycasting methods. I would expect the raycast on the proxy tiles to be a performance hit, but not sure what would be acceptable. Here's how I was testing, then processed the measures in the console. override raycast(pos: vec3, dir: vec3, exaggeration: number): number | null | undefined {
if (!this._visibleDemTiles)
return null;
performance.mark('startRaycast');
// Check if we're overzoomed (display zoom > DEM source maxzoom)
// In this case, proxy tile raycast provides more accurate results
const sourceCache = this._source();
const isOverZoomed = sourceCache && this.painter.transform.zoom > sourceCache.getSource().maxzoom;
let tag = ''
if (isOverZoomed && this.proxyCoords && this.proxyCoords.length > 0) {
const result = this._raycastWithProxyTiles(pos, dir, exaggeration);
if (result != null) {
performance.mark('endRaycast');
performance.measure('raycastWithProxyTiles', 'startRaycast', 'endRaycast');
return result;
}
tag = 'RanBoth'
}
const defaultRaycast = this._raycastWithDemTree(pos, dir, exaggeration);
performance.mark('endRaycast');
performance.measure(`raycastWithDemTree${tag}`, 'startRaycast', 'endRaycast');
return defaultRaycast;
} |
Issue
When using terrain with a DEM source that has a lower maxzoom than the current display zoom (e.g., DEM maxzoom of 10 while viewing at zoom 14), the
pointCoordinateraycast was not consistent with the rendered terrain. This caused issues where clicking on the visible terrain surface would return incorrect 3D coordinates.{"type":"raster-dem","tiles":["https://example.tile.server/v1/terrain/{z}/{x}/{y}.png"],"tileSize":256,"maxzoom":10,"encoding":"terrarium"}bug-raycast-on-overscaled-tiles.mov
Solution
The raycast now uses a proxy tile-based approach when overzoomed, which matches the exact geometry rendered by the terrain shader.
fix-raycast-on-proxied-tiles.mov
API Changes
No API Changes
Launch Checklist
Initial Draft
Intent is to show the issue and potential fix for support request 176617. Happy to add some tests, I did some rudimentary benchmark tests but this needs to be done a bit more in depth.