Repository navigation
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. |
lbud
left a comment
There was a problem hiding this comment.
Looks sharp to me! (GPU: Intel Iris Graphics 550 1536 MB)
| 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.
🤔 would we not want to use the alignedPosMatrixCache result if it's available?
There was a problem hiding this comment.
Ah, good catch. That’s an artifact from a different approach I tried.
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:

after:

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.