-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align projection matrix to pixel grids to draw crisp raster tiles #6026
Conversation
673d15c
to
6ab7c20
Compare
6ab7c20
to
918f7ec
Compare
Update: changed this PR so that it only pixel-grid-aligns raster tiles. On my machine, this produces perfectly crisp output on regular and retina screens in all browsers and for all viewport dimensions. |
Testing-wise, it'd be cool to have a few people with different GPUs test this change. For this purpose, I've checked in a http://localhost:9966/debug/raster-streets.html#3/0/0 file. Use (shift-)double-click to zoom in(out) to remain on integer zoom levels (or manually manipulate the hash). |
918f7ec
to
e5dbcd4
Compare
Also added the ability to draw crisp rasters at 90 and 270 degrees rotation + tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sharp to me! (GPU: Intel Iris Graphics 550 1536 MB)
src/geo/transform.js
Outdated
if (this._posMatrixCache[posMatrixKey]) { | ||
return this._posMatrixCache[posMatrixKey]; | ||
const cache = aligned ? this._alignedPosMatrixCache : this._posMatrixCache; | ||
if (!aligned && cache[posMatrixKey]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 would we not want to use the alignedPosMatrixCache
result if it's available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. That’s an artifact from a different approach I tried.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix!
e5dbcd4
to
9f1405f
Compare
cc @pdgoodman @aag6z |
Amazing work @kkaefer |
Thanks @kkaefer! |
This changes our projection matrix to be aligned to the pixel grid to fix blurry raster tiles at integer zoom levels (#4552).
While this change works great
before:
![expected](https://user-images.githubusercontent.com/52399/35168392-a1ddaae6-fd0d-11e7-9ecc-dc7ade437f82.png)
after:
![actual](https://user-images.githubusercontent.com/52399/35168395-a52e9b74-fd0d-11e7-9c35-5cd7134d876e.png)
and produces the same level of crispness as a Leaflet map of the same raster tiles, it also changes the behavior of some of our APIs: it is no longer possible to roundtrip a point through our transform object and get the same result back, since all transformations are now aligned to this pixel grid. It also slightly shifts rendering of all other items (shapes, lines, symbols) by up to half a pixel, which results in hundreds of rendering "errors".
One way to solve this would be to use the pixel-aligned projection matrix only for raster (and terrain?) tiles. However, this means that our raster tiles might be shifted by up to half a pixel compared to the rest of the data we are drawing on the screen. In reality, I doubt that this will be noticeable, but something we should consider before merging this.
A notable discovery is that pixel alignment of our map depends on whether the viewport has even or odd dimensions.