Repository navigation
fix: Use fp64 emulation to fix lack of precision (jitter) at high zooms - #559
Merged
Merged
Conversation
Adds the design doc for the fp64 attribute-pair approach to the high-zoom jitter problem, plus a new dev-docs/coordinate-systems.md that captures the deck.gl precision machinery and the gotchas we hit exploring earlier approaches (per-tile offsets, auto-offset's Math.fround floor, the SimpleMeshLayer small-model-big-anchor assumption, fp64-extension vs fp64-attribute-pairs). The earlier exploration branch (kyle/fix-zoom-precision-issues) is preserved as historical reference; this branch starts fresh from main.
Corrects the wiring section: BitmapLayer's AttributeManager auto-split doesn't apply to SimpleMeshLayer (Geometry-driven for primitive attrs, normalizeGeometryAttributes whitelists four names). Replaces with the actual approach: pre-split on CPU, plumb high through mesh.attributes.POSITION, low through a new MeshTextureLayer prop registered via attributeManager.add. Adds an Invariant subsection documenting that the fp64 correction holds only when SimpleMeshLayer's per-instance transforms are identity (true for RasterLayer's current usage). Spec now requires the implementation to add a dev-mode assert that throws on misuse. Tightens the precision test bound to <1e-6 m absolute, vs the current <1m float32-of-input floor.
…512) Pre-split each float64 vertex coord into Math.fround(v) (high) and v - Math.fround(v) (low), both Float32Arrays. The high part flows through state.mesh.attributes.POSITION as today; the low part is stored as a state.positions64Low sibling for downstream wiring. Nothing consumes the low part yet — render behavior is identical to main. Sets up Stage 2 to plumb it into MeshTextureLayer.
…fp64 (#512) MeshTextureLayer registers a positions64Low per-vertex attribute via attributeManager.add (non-instanced), reads it from a new prop fed by RasterLayer, and overrides SimpleMeshLayer's vertex shader to pass it through to project_position_to_clipspace's existing position64Low parameter. End-to-end float64-equivalent mesh vertex precision on float32 GPU hardware. A dev-mode assertion (assertFp64Invariants) throws if SimpleMeshLayer's per-instance transforms aren't identity — the fp64 correction is only valid when positions equals pos in the shader.
…lts (#512) SimpleMeshLayer.defaultProps sets getOrientation: [0,0,0], getScale: [1,1,1], getTranslation: [0,0,0], getTransformMatrix: []. Checking !== undefined fires under normal RasterLayer usage because deck.gl fills in those defaults. Check against the identity values instead, and reject function accessors (which we can't safely evaluate without data).
deck.gl 9.x removed props.<attrName> as a channel for attribute values
(@deck.gl/core/lib/attribute/attribute-manager.ts:196). Our previous
top-level `positions64Low` prop on MeshTextureLayer triggered the
removal warning at every render.
Drops the prop, leaves the attribute registration in
attributeManager.add (without an update callback), and pipes the
Float32Array via the inner TileLayer sub-layer's
`data: { length: 1, attributes: { positions64Low } }`. The attribute
manager picks up the buffer via setExternalBuffer.
) fp64 attribute pairs alone don't fix the cartesian high-zoom jitter: there are three float32-at-large-magnitude error sources, and fp64 only addresses the attribute quantization. The scale-multiply (A) and the auto-offset origin re-quantization (B) remain a ~1m floor. Documents the full fix: project mesh vertices to common space on the CPU (identity modelMatrix kills the multiply), set coordinateOrigin to [0,0,0] (makes shaderCoordinateOrigin exactly fround(viewport.center), no upload re-quantization, Sterbenz-exact subtraction), keep the fp64 pairs for the attribute. This reproduces deck.gl's LNGLAT precision discipline in common space. Adds the analysis to coordinate-systems.md.
…ecision (#512) Non-globe tiles now render directly in deck.gl common space (world units) instead of EPSG:3857 meters: forwardReproject/inverseReproject are wrapped to apply `meters * scale + TILE_SIZE/2`, so modelMatrix is identity and coordinateOrigin is [0,0,0]. Combined with the fp64 mesh-vertex split, this eliminates all three high-zoom precision floors: no scale multiply in the shader (identity matrix), shaderCoordinateOrigin is exactly fround(viewport.center) (zero origin → no upload re-quantization → Sterbenz-exact subtraction), and the attribute residual is restored by the fp64 low part. The wrapped fns are memoized per-descriptor for reference stability (else RasterLayer regenerates the mesh every frame). Delatin's pixel-space error metric is unchanged because barycentric interpolation commutes with the affine and inverseReproject undoes it.
kylebarron
commented
May 20, 2026
) - Extract a vectorized splitFloat64(Float64Array) -> [low, high] helper (+ test) instead of inlining the fp64 split in reprojectorToMesh. - Simplify the non-globe deckProjectionProps to just { coordinateSystem: "cartesian" } — identity modelMatrix and [0,0,0] coordinateOrigin are deck.gl defaults now that positions are in common space. - Drop the dead positions64Low null-branch in renderLayers (it's always set alongside state.mesh). - Replace the runtime assertFp64Invariants check (and its NODE_ENV gate) with type-level exclusion: MeshTextureLayerProps omits the per-instance placement props, defaultProps fixes _instanced/getPosition, and the class doc explains the divergence from SimpleMeshLayer. Delete the assertion file + test. - Comment why the common-space offset is TILE_SIZE/2. - Fix the COORDINATE_SYSTEM doc link (lib/constants.ts with line range) and reword the permalink note (SHA-pinned links don't drift).
kylebarron
commented
May 20, 2026
The deck.gl source references introduced in this PR were pinned to
main-branch commits (82a02831, 48760d53) that postdate the 9.3.2
release we actually depend on — 48760d53 ("Row index based picking",
PR #10275) even removes the instancePickingColors attribute our copied
vertex shader relies on. Repoint all of them to the v9.3.2 tag commit
09af8de8, where the cited line numbers match the installed source.
…512) Moving the mesh to common space broke coordinate-based clipping in two examples, which compared against vertex positions in EPSG:3857 meters. CutlineBbox.bbox is now a common-space [minX, minY, maxX, maxY], and getUniforms is a pure pass-through. Projection is intentionally NOT done in getUniforms: luma.gl's ShaderInputs.setProps calls getUniforms on every draw (every animation frame), so any projection there would run per frame. Callers project a WGS84 bbox once at definition time using deck.gl's own helpers — no hand-rolled mercator math. BREAKING: bbox is common space (was 3857 meters); the lngLatToMercator export is removed. - usgs-topo-cutline: project the static quad bboxes once at module load via WebMercatorViewport.projectPosition. - vermont-cog-comparison: splitMercatorMeterX -> splitCommonSpaceX using viewport.projectPosition; clip extent is the [0, 512] common-space world instead of ±MERCATOR_HALF_EQUATOR.
The non-globe render path memoized its source-CRS → common-space reprojection closures on a layer instance field. deck.gl recreates the layer instance every render and transfers only `state`, so the memo missed each render, producing fresh closures whose reference instability tripped RasterLayer's `reprojectionFnsChanged` check — regenerating the mesh and recompiling the shader on every frame (visible as time spent in stripShaderComments / getGLSLUniformBlocks while dragging the vermont comparison slider). Build the projection once on RasterTileset2D and expose it on each tile's RasterTileMetadata as `_projectPosition` / `_unprojectPosition` (named after deck.gl's `Viewport.projectPosition` / `unprojectPosition`), alongside the existing per-tile `forwardTransform` / `inverseTransform`. Tiles are cached across renders, so the references stay stable and the mesh is no longer regenerated per frame. The common-space rescale math now lives solely in the tileset module (`rescaleEPSG3857ToCommonSpace` plus a new inverse), removing the duplicated constants. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
kylebarron
marked this pull request as ready for review
May 20, 2026 21:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After: smooth, high-precision zoom in/out without any jitter!
Screen.Recording.2026-05-20.at.5.24.29.PM.mov
Before:
Screen.Recording.2026-05-20.at.5.23.41.PM.mov
Screen.Recording.2026-05-07.at.10.08.40.AM.mov
Summary
Fixes #512 — raster tiles jittered and drifted off the basemap above ~z16 over high-resolution imagery (sub-meter NAIP).
Root cause: mesh vertex positions in EPSG:3857 meters (~10⁷ magnitude) quantize to ~1 m when written into a float32 GPU attribute. Two further float32-at-large-magnitude steps in deck.gl's cartesian + auto-offset shader chain compound it (the scale multiply, and the auto-offset origin re-quantization).
Fix — eliminate all three float32 error sources:
forwardReproject/inverseReprojectare wrapped to applymeters × scale + TILE_SIZE/2(memoized per-descriptor for reference stability), somodelMatrixis identity (kills the scale-multiply rounding) andcoordinateOriginis[0,0,0](soshaderCoordinateOriginis exactlyMath.fround(viewport.center)→ no upload re-quantization → Sterbenz-exact camera-relative subtraction).position64Lowpath) recover the attribute quantization.Shared boundary vertices stay bit-identical across adjacent tiles (absolute common-space coords + deterministic split), so there are no tile seams. Delatin's triangulation is unchanged: its error metric is in pixel space, and the affine wrap commutes with barycentric interpolation.
A dev-mode assertion guards the
SimpleMeshLayerper-instance-transform invariants the fp64 correction relies on. The full error analysis and deck.gl precision background are documented indev-docs/coordinate-systems.mdanddev-docs/specs/2026-05-19-high-zoom-precision-design.md.Previous attempt
#558 records the per-tile-reference-point approach that didn't work (tile seams + no real precision gain over
main) — closed and kept for reference.Test plan
pnpm --filter @developmentseed/deck.gl-raster test) — fp64 split reconstruction (<1e-6 m), invariant assertion🤖 Generated with Claude Code