Skip to content
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

Background is not properly tiled and blurry #1650

Closed
Nekzuris opened this issue Dec 20, 2024 · 2 comments
Closed

Background is not properly tiled and blurry #1650

Nekzuris opened this issue Dec 20, 2024 · 2 comments
Labels
feature-renderer Issue or request related to the renderer / WebGL
Milestone

Comments

@Nekzuris
Copy link

Description

I noticed that the tiles are very blurry and not properly tiled, not a big deal with real imagery, but quite noticeable with text like Mapnik Carto.

With canary the blur is almost gone but still not properly tiled.

I haven’t yet looked at the renderer code, but you probably just need to remove a small scale factor applied on every tiles.
This scale factor is typically used to hide gaps between tiles on Chrome due to this bug but might no longer be necessary and is definitely not needed on Firefox.

For reference I've done this for iD openstreetmap/iD#10594

Screenshots

Blurry and visible tiles on rapid
rapid line
Sharp and properly tiled with leaflet
osm
https://www.openstreetmap.org/#map=18/48.272140/7.052858

Version

2.4.3

What browser are you seeing the problem on? What version are you running?

Firefox v133.0

The OS you're using

win

Steps to reproduce

Open the editor and look closely (hide data layer).

The browser URL at the time you encountered the bug

https://rapideditor.org/edit#map=18.00/48.27224/7.05398&background=MAPNIK&datasets=fbRoads,msBuildings&disable_features=boundaries

The auto-detected useragent string for your browser (leave blank if you're manually filling this form out)

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0

@bhousel
Copy link
Contributor

bhousel commented Dec 20, 2024

Thanks for reporting @Nekzuris - we can look into it.
The way Rapid renders tiles is very different than how iD and Leaflet renders them, so there might not be much that we can do.

iD and Leaflet create a slippy map of img elements, and as you found Chrome sometimes rounds the dimensions of these incorrectly, that's why I added that small epsilon to close the seams a long time ago.

Rapid actually packs the image data into an atlas texture and uploads these images to the GPU. We can render the tiles at exactly the correct size, however we offset the texture coordinates by half a pixel so that the texture doesn't bleed into neighboring images in the atlas - this is probably what is causing the blurriness. It will always be a very tiny bit blurry, but there should never be seams from neighboring textures or empty parts of the atlas.

@bhousel bhousel added the feature-renderer Issue or request related to the renderer / WebGL label Dec 20, 2024
@bhousel
Copy link
Contributor

bhousel commented Jan 3, 2025

I've been working on this today and I came up with a workaround that lets us avoid the half-pixel correction trick from my previous comment.

We can add 1px padding around each texture, then write actual image data into the padding so that when the texture is sampled at the correct size, it doesn't bleed into the neighboring texture in the atlas.

It works ok! I had to zoom into z21 (#map=21.00/48.27217/7.05060), to really see the difference, but it is nice to be able to display the background imagery faithfully instead of slightly squooshed:
avoid seams

The code is a bit experimental. I am brute-forcing the copying by just calling texSubImage2D a bunch of times.
This seems to work fine, but it's probably inefficient, so I'm going to profile a bit and try a more performant method before closing this issue.

bhousel added a commit that referenced this issue Jan 6, 2025
The goal here is to eliminate the half-pixel correction that we used before to
close the seams between imagery tile textures packed into the atlas. see 4e8f16b

While it does prevent the colors from bleeding into the neighboring texture,
it distorts the image a little bit - this is especially visible when zoomed in.

Instead, we'll do this:
- Just add 1px of padding to everything packed into the atlases
- For imagery tiles, duplicate the edge data into this 1px padding, so when the tiles
  are sampled, they blend with the padding, not the neighboring texture.

I tried it and it works ok - but my method of filling the padding is inefficient.
I'm just calling `texSubImage2D` a bunch of times with the full image.

Will followup this commit with something more efficient that only writes the
pixels we need.
@bhousel bhousel closed this as completed in d19702f Jan 6, 2025
@bhousel bhousel added this to the v2.5.1 milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-renderer Issue or request related to the renderer / WebGL
Projects
None yet
Development

No branches or pull requests

2 participants