mapbox / mapbox/mapbox-gl-js

Working with 64-bit float resolution in custom layers (fix flickering/jumpyness/wobbling)

Open
#8,709 3 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api :memo: feature :green_apple: needs discussion :speech_balloon:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I have a proposal on how to implement a solution to these problems without sacrificing much performance and not bloating the code:
https://github.com/mapbox/mapbox-gl-js/issues/8593
https://github.com/uber/luma.gl/issues/1211

[my jsfiddle example](https://jsfiddle.net/cyrili/jqw1msLc/8/) based on the ["add a custom layer" example](https://docs.mapbox.com/mapbox-gl-js/example/custom-style-layer/)

at every frame the eye/camera coordinate is calculated from the view-projection matrix by finding the coordinate (x,y,z,1) that maps to (0,0,0,w_clip). This step could be easier if mapbox exposed camera position..

this coordinate has the advantage that (at high zoom levels) it is close to vertices being rendered. And subtracting it from the vertex coordinate does not change the x,y,z clip coordinates after transformation.

this eye/camera coordinate + its w_clip value are split up into two non-overlapping 32bit floats to emulate one 64bit float and sent to the vertex shader. The same is done at init time for all vertex coordinates (so that they can be positioned with 64bit precision).

the vertex shader takes this approach to calculate the difference between camera and vertex position: diff = (vertex_high - eye_high) + (vertex_low - eye_low). This is allowed since subtracting the two high floats (always positive) from each other can't result in loss of precision (the precision of the low floats is not as important).

as a last step the error introduced in the w_clip coordinate is corrected.

These steps are inspired from a couple text posts describing how to "add an offset to the coordinates". I want to share my implementation and would like to hear inputs on how to improve it, as a few people have already run into this problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the custom style layer example and the linked discussions in mapbox-gl-js#8593 and luma.gl#1211, then review the jsfiddle implementation. Determine whether exposing the camera position and applying the proposed 64-bit coordinate handling fits the custom-layer API; done means an agreed implementation that prevents high-zoom flickering, jumpiness, and wobbling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
computer-graphics, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.