Description
I've been experimenting with @ansis' recently merged Custom Style Layers. They're a great addition, but I've noticed what looks to be jitter at high zoom levels due to (I presume) floating point precision issues.
This can be seen in the provided custom-style-layer.html
example. Simply zoom into the red quad (>= 16 zoom) and you'll notice it starts to jitter as the zoom level increases.
If this is indeed a precision issue are there plans to mitigate this? I've seen faked double precision (sometimes referred to as relative-to-eye rendering) used to mitigate similar issues in the past.
I'd be interested to hear if this is something you guys are hoping to address, or if you have any suggestions as to how best to work around the issue for the time being.
Activity
ansis commentedon Sep 12, 2018
@measuredweighed yep, this is a precision problem! Thanks for opening this issue.
Internally we avoid this precision issues by storing coordinates in a more local coordinate space and transforming the matrix to work with that coordinate space. The high precision math is done in js while transforming the matrix.
The threejs example does this here.
This approach is pretty simple if everything rendered is pretty close together. If you need a global layer with high precision you need to implement some sort of tiling with this approach. And that can get complex.
I think we might want to add some sort of support for helping create these matrices. If you think this approach would work for you it would be helpful to hear what would be useful to add to fix this.
Yep. I don't personally have experience with this approach but it might be possible to use this together with the matrix. I think you could do fake double precision math when projecting the position with the matrix?
measuredweighed commentedon Sep 12, 2018
@ansis Thanks for getting back to me so promptly! We are indeed looking for a global layer with high precision - which is part of the reason why I was confident this might be precision related (as we've run into similar issues in the past).
I took a run at augmenting the custom-style-layer example to support a version of relative-to-eye rendering (where we basically adjust the matrix provided to centre the eye at
0,0,0
and then use faked double precision in the vertex shader to render relative to the current map center).The code is a little rough, but it does seem to work nicely in testing (I've moved null island to London's Heathrow airport for this test as the jitter is easier to detect over land).
I'd be interested in helping to nail down a generic solution, as this is something we're keen to use in production.
MercatorCoordinate
type #7488lileialg commentedon Oct 31, 2018
@measuredweighed### I really appreciate that
lileialg commentedon Nov 1, 2018
@measuredweighed When I rotate the map, the position of the point is wrong,Do you have any other method?
peterqliu commentedon Nov 1, 2018
@lileialg @measuredweighed check out https://github.com/peterqliu/threebox for a third-party library connecting three.js to mapboxgl. It addresses many of the camera precision and coordinate issues that are common to this task
lileialg commentedon Nov 1, 2018
@peterqliu I convert position to pixel in javascript instead of in shader script,It looks like working fine,But much more calculation in javascript.
custom3d-13.txt
herewaitting commentedon Feb 23, 2019
Hi,
I used your method to solve the problem of accuracy, but at the same time another problem arises. The orientation of the camera can only be perpendicular to the map. Otherwise, the drawing layer will not be seen. How to solve this problem at this time?
Thanks
11 remaining items