As I've explained before, this will work differently from the original, flat-world version of UW. In that version you could view the global map, select a point on it, and zoom in to see the regional map of that part of the world, in a separate screen. But this wouldn't work very well for a spherical world, where we will instead display regional maps directly on the globe itself. As you zoom in, the details of the regional maps will become visible. So it should all operate seamlessly. That's the theory anyway!
This means we need the ability to generate and display multiple regional maps at once. It's not possible to store regional-scale information for the entire planet, since a large world has 16 x 16 regions on each face, making 1,536 regions in all. We can store only a fraction of these at once. So what we need is a system whereby the program can dynamically create new regions as the user moves around the world, deleting them when they're no longer visible.
After many false starts I've got the basics of this system up and running. We have a stable of threads dedicated to generating regions and drawing their maps. As the user views the globe, these threads work in the background to create regions roughly where the user is looking, with unused ones being discarded. Meanwhile, the main thread displays the regional textures where they exist, and the lower-resolution global textures where they do not. This way, if the user is zoomed in enough to make out details at the regional scale, they should be able to see only regional textures visible on the screen.
Now I haven't yet started translating the actual region creation functions so that they work with spherical worlds, because I wanted to get this system up and running first and then plug in the region creation functions as I convert them. So at the moment the region creating threads are just applying a placeholder texture (of parrots, because why not). But here is a pretty rough-and-ready (and somewhat nausea-inducing) video showing the system in action.
As you can see, as we move around the planet (or rotate the planet itself) the more distant regions are deleted and replaced with closer ones. If you zoom in closely, it creates the illusion that the entire world is covered with nothing but parrot images, because you can't see the edge of the patch of textures.
Now all I need to do is to convert the existing region-creation functions from the old version of UW. For the most part this should (I hope) involve changing them so they take their raw data from the spherical world object instead of a flat one. This will be tricky at the edges of faces, because the regions as generated are a bit larger than what you see. This is because some elements of the tiles that compose the regions overlap from tile to tile, so when we generate a region we need to generate the tiles along the edges of its neighbouring regions, in case anything from them overlaps onto our region. In a flat world this is fine, but here we're going to have regions along the edges of faces of the cubesphere, which means we have to take into account the fact that tiles from the next face along might be rotated relative to the active face, and that complicates matters.
That probably makes very little sense. Still, I'm glad to have the framework for regions set up now, so I can focus on getting back to map generation...
This is looking great! Is there any chance you could post a beta release on github? I'm dying to goof around in this :D
ReplyDeleteHa, maybe! There's quite a bit of polishing needed though to make it generally useable (so many elements are currently commented out) so if this happens it won't be immediate.
DeleteOn second thoughts, why not bung it out there anyway? I've just uploaded the code to github - will make a new post now outlining it.
DeleteI'd have gone with turtles myself but to each his own.
ReplyDeleteIt's interesting how clear the edges of the cubesphere are amid the tiled texture, but you'd never know looking at the maps. Are you regenerating the same regional maps from scratch each time they're needed? Depending on how cpu- vs memory-bound the process is, you might consider caching them to a file.
Yes, I'm realising that distortions are apparent only when the edges are made apparent in this way (or when texels are large). So I'm quite hopeful that one I get the regional-level of detail working, the planets should look quite convincing. At the moment if you zoom in far enough the texels become too apparent and then the edges of faces are more discernible.
DeleteYes, the regions will be regenerated from scratch each time. I hadn't thought of file-caching for this - this is because I've found, at least with global maps, that reading/writing the files takes a comparable amount of time to just regenerating them. There's a lot of data involved! Once I've got the regional creation working I might try using a save system to see if it's quicker, but I suspect that it won't be. Anything's worth trying though!