mapbox-gl-js
mapbox-gl-js copied to clipboard
Working with 64-bit float resolution in custom layers (fix flickering/jumpyness/wobbling)
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 based on the "add a custom layer" example
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.
Thanks for diving into this problem!
This step could be easier if mapbox exposed camera position..
Do you have a proposal for how exposing the camera position could look like?
Do you have a proposal for how exposing the camera position could look like?
instead of handing over the "matrix" variable that contains view * projection transformations in one, hand over each separately to the renderer function. "function renderer(gl, mat_view, mat_proj)". Then it becomes trivial to extract the camera position (and other info about the camera beside that).
Is there any update on the flickering fix? The jitter issue is still there on the mapbox custom layers example page.