astrosat / windgl

A WebGL wind particle simulation as a Mapbox custom layer
https://astrosat.github.io/windgl/
ISC License
170 stars 45 forks source link

SampleFill faulty rendering on different browsers #18

Open maeneak opened 5 years ago

maeneak commented 5 years ago

Tiles are not rendering at certain positions and zoom levels on different browsers. Seems to be fairly random. Can be reproduced using the current demo at https://astrosat.github.io/windgl/

maeneak commented 5 years ago

Im fairly sure this is relating to the tiling. When the tiles do display they display correctly along all longitudes but only on 90deg section along the latitude. Strangely the latitudes are different on different browsers. 90N to 0 in firefox and 45N to 45S in chrome and edge. My guess would be computeLoadableTiles() as it is overriden in particles which is functioning as expected.

maeneak commented 5 years ago

There's quite a lot going wrong with this. I've identified definite issues with the tile calculations in layer.computeVisibleTiles() but even when fixing this the problem persists. I'm convinced this is a shader issue, possibly relating to the reprojection functions, but my GLSL skills are sketchy at best.

gampleman commented 5 years ago

Yeah I've noticed that as well. TBH I'm fairly convinced that some of these issues might even be in mapbox itself, although it's hard to prove. I've even seen inconsistent behavior based on different screen sizes.

As a workaround, it's probably best to specify a reasonably high min-zoom.

maeneak commented 5 years ago

I can confirm this bug is in the Projections in the Shaders. Changing the vertex position to worldCoordsWGS84 from worldCoordsMerc extends the tiles the full lat range but puts the projection out. Might need someone with a better understanding of the code to look at this.

    v_tex_pos = worldCoordsWGS84;
    gl_Position = u_matrix * vec4(worldCoordsWGS84, 0, 1);
maeneak commented 5 years ago

So i managed to find a pretty nifty little hole/hack in the mapbox-gl source code which allows me to use the built in mapbox tile system to feed textures to custom shaders from a custom layer. I've created a repo with a simple demo, this would be a good fit with this project and would eliminate many of the alignment and browser related issues. Mapbox takes care of all texture loading, tile matrix calculations, projection and tile caching which will reduce the code base significantly. Ill be using this method in my own project but will try to throw some time at a branch of the current master and post if i make some progress. This would obviously require a revamp of the py generator code (not my forte) but ill try to use static tiles from a WMS source as test data.

gampleman commented 5 years ago

I found those hacks as well, but in this case we are using unprojected data, so the tiles end up being different.

maeneak commented 5 years ago

Ahh ok of course. I'm using a tile server which is doing it on the fly. I'm sure there would be plenty of py modules that could do the projection in pre-processing? Anyway ill leave it for now 👍

gampleman commented 5 years ago

Of course, but some of the math seemed easier to do correctly in WGS84 than in Mercator. Having now done the project, I think I might reconsider that decision, but at the time it seemed like a reasonable choice.