deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

TileLayer with BitmapLayer

Open mbarrenechea opened this issue 7 years ago • 13 comments

Hi,

I tried to use a combination between TileLayer and BitmapLayer because I want to parse each pixel of a Raster.

The thing is that I managed to show it on the map applying my decode function => https://github.com/mbarrenechea/mapbox-sandbox/blob/master/src/components/bitmap-layer/bitmap-layer-fragment.js#L37

The problem is that my raster images seem to be blurred. Even if I don't apply my decode function, the result is the same, so I discarded that the problem is on my decode function.

image.

The desired result should be this one that you can see here In this case, we are using leaflet + canvas to decode each of my raster images

https://github.com/mbarrenechea/mapbox-sandbox

What do you think? Do you think is possible to do that? Thank you in advance

mbarrenechea avatar Feb 22 '19 08:02 mbarrenechea

the blur is from texture filtering, you can try to set the texture parameters as const TEX_PARAMETER = { [GL.TEXTURE_MIN_FILTER]: GL.NEAREST, [GL.TEXTURE_MAG_FILTER]: GL.NEAREST, [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE, [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE }; and disable mipmaps Here is the Texture2D doc

jianhuang01 avatar Feb 25 '19 19:02 jianhuang01

hi @jianhuang01 thanks, for responding to this. I have been working on this with @mbarrenechea.

I have followed your response and looked through the docs for the Texture2D but no options seem to prevent the blurring on the tiles images. I have found that applying the parameters you specified seems to prevent the blurring of the textures when at zoom levels beyond the max zoom (in this case 11). We have tiles up to zoom 11. I have attached a gif of starting at zoom 12 and zooming out to < 11 to show you the difference. I have also attached an image of what the tiles look like without being passed through out custom decode as that shows better the individual textures with the added darkening and blurring around the edges.

Zooming: 2019-02-26 15 04 17

The blurring effect at high zoom: screenshot 2019-02-26 at 15 11 00

Any thoughts on why would be greatly appreciated!

edbrett avatar Feb 26 '19 14:02 edbrett

Hi @edbrett. It looks like mipmapping is still enabled there. Do you have a live version of your app available somewhere? Might be able to narrow this down if I run it through some inspection tools.

tsherif avatar Feb 26 '19 16:02 tsherif

Hi @tsherif, thanks for getting back. I have just pushed on master the latest of what we are working on with the above suggested changes here: https://github.com/mbarrenechea/mapbox-sandbox.

I don't have anything deployed but this should be easy to clone and run.

edbrett avatar Feb 26 '19 16:02 edbrett

@edbrett Played your app for a while, downloaded two pngs from the data source, opened by macbook Preview app and zoom in. Image from zoom 12 image Image from zoom 10 image As you see above, the raw png from zoom 10 already has blur blended.

By the way, I can't run the app by simply clone your repo, because of wrong file paths like import Map from 'components/map'

jianhuang01 avatar Feb 26 '19 21:02 jianhuang01

If you want to run the app, remember to create a file named .env in the root with the .env.sample content. It's on the readme.

Thank you so much for helping us, tomorrow we will try another source for the tiles

mbarrenechea avatar Feb 27 '19 00:02 mbarrenechea

@jianhuang01 I have been looking at the source tiles also and comparing them. You are correct from the example you gave that there is some alpha on the source tiles below z12, but the issue we found with this was something else. I found that if you decode the tiles and return a vertex with alpha set to 1, then there is no blurring effect at any level, but when you apply an alpha, therefore meaning that pixels that are next to each other have a different colour, there is some artefacts shown in the blending of those colours. To demonstrate this I used a different layer that has better colour contrasts.

Layer source tile from source: 2c4fde29-1627-40eb-96b5-a9e388f7c7b7_10_363_606_tile_269c842b01900a59075f395b44be3bb0

GL decoded layer without alpha (set alpha band to 1 on all pixels): screenshot 2019-02-28 at 15 21 27

GL decoded layer with alpha applied (variable alpha): screenshot 2019-02-28 at 15 21 43

We played around with the settings for the textures for a while but couldn't find anything that improved the blending of the opaque pixels. However, one thing we did notice inside the TileLayer we inherited from the experimental layers is that we might be accessing the incorrect tiles for the given zoom. We noticed in the raster layer in mapbox itself when taking a raster source, they fetched the tiles at the .ceil() of the current zoom float, but in the TileLayer we are getting the .floor(). We changed this and made some modifications to the viewport calculations and it seems to improve the resolution of the tiles in view significantly. Example: screenshot 2019-02-28 at 15 22 07

After also fixing our decode function within our shader, we managed to get the original layer looking as we wanted. Here it is with an animation applied: 2019-02-28 12 09 32

In summary we feel we have found a solution by changing the tiles that are fetched for a given zoom, but there does seem to be some noticeable colouring when blending tiles with variable alpha between adjacent pixels. If this can be improved, or you have any suggestions on how to sharpen blending of alpha on pixel we would be very grateful!? Otherwise we are happy with what we have.

edbrett avatar Feb 28 '19 14:02 edbrett

Sounds like you may want to try changing blend settings. Using the parameters prop on the layer you can control any WebGL settings including all blend settings, some examples:

        parameters: {
          blendEquation: GL.MAX
        }
   parameters: {
      blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
      blendEquation: gl.FUNC_ADD
   }

etc.

For more information see luma.gl docs and any WebGL article about blending. I wish we had a good guide, unfortunately, blend settings are not exactly trivial to understand/explain, but often one can get significant improvements in visuals by using them, so worth playing around.

ibgreen avatar Feb 28 '19 18:02 ibgreen

@edbrett Glad to see you have progress, actually I don't know how you decode the data, that's not our API, so can't help on that area.

jianhuang01 avatar Feb 28 '19 22:02 jianhuang01

@mbarrenechea have you ever load a mapbox tile layer?
#3329 I tried load a building layer published by geoserver ,could help have a look?

HeiYanjing avatar Jul 17 '19 10:07 HeiYanjing

@HeiYanjing no, our source of data is a raster tile layer. I'll take a look at your code, but it doesn't seem to be related

mbarrenechea avatar Jul 17 '19 11:07 mbarrenechea

@mbarrenechea thank you!

HeiYanjing avatar Jul 18 '19 01:07 HeiYanjing

Closing issue as I believe @ibgreen's last response answers the remaining question about how to control alpha blending on a layer using the parameters prop.

tgorkin avatar Aug 06 '19 20:08 tgorkin