Project mercator tiles on to sphere
Opened this issue · 9 comments
Hi, thanks for this great project.
Since mercator projected tiles don't map on to the sphere, I was wondering if you could recommend a tileset that is warped to fit on to it?
I took a look at the Cesium viewer (which I'm trying not to use, because I want to keep using three), and according to the network traffic, it's loading in the same tiles from Bing. That is to say the tiles are for the web mercator projection, and the application is warping them to fit the sphere. It is also my understanding that Google Earth more or less does the same thing.
I'm going to check out the Cesium source code a bit and see how what's going on underneath. Will let you know what I find.
It seems like Cesium is setting up a WebGL texture, and computing the color value of each pixel by converting its coordinates to mercator, and then sampling the mercator tile pixel at that coordinate.
I wrote a python script to test this projection out, using the following tile.
First, the current geo-three projection
Here the script projects the tile on to a sphere first naively (mostly matches the geo-three projection, though I forgot to leave out the region where mercator is invalid, I corrected that before doing the projection below)
Lastly, using described projection method, the results look like this:
I think it looks pretty good. Here's Cesium for comparison:
The next step would to try to make a Shader material that does this calculation and lookup in real time. I'll try to give that shot.
In case anyone is curious, the place they do that in Cesium, while spread across multiple files, I would say for the most part happens here (they describe the calculation in comments here at least): https://github.com/CesiumGS/cesium/blob/cbd13cee0959d2de6e01f355dd1cd73342467102/packages/engine/Source/Scene/ImageryLayer.js#L1506
Okay, did a quick proof of concept by hardcoding some stuff for this tile, here's how it looks:
I will try to generalize it so that it works on all the other tiles, and I'll make a PR.
I am still curious if the tiles should have equal heights, or if that will cause problems from zooming in with this projection, hopefully we'll find out soon.
Getting really close now.
The problem above is caused by the size of the geometric tile section on the sphere's surface not matching the expected bounds for the mercator image tile. I was able to fix that for latitude and now tiles load nicely with zoom... to a point.
There is still a misalignment for longitude at higher zooms, shown here. Tackling this next.
I got it :)
Things are looking pretty good even at high zooms, although a small border is still visible at those levels.
Here's a video of the LOD adjusting while zooming in (although not as nicely as possible).
https://github.com/tentone/geo-three/assets/3690500/28c9d69f-47a1-4d17-bcb1-e59d78c96f83
There's also a visible seam at the international date line still.
I'm hoping this is good enough for a PR, so I'm going to clean everything, make a fork, and open one up.
Hello
Wow, you have done an impressive ammount of work here 👍
Will be more than happy to help you finishing and merging this code into the library.
This was something that was discarded on the first version because of tile fit, the way sampling is done this way seems to work nicely.
Hello!
I have use current code run a demo , and haven't modify anything, but there are some misalignment , Is there some error?
@cmurphy23