stereographic projections for spherical planets
okay, so, i really only worked on this for a few hours, rather than a solid two weeks, but i'm still counting this as something. but that does make this more of a problem statement than something with extensive code fragments.
so, okay. several years ago i put together a skybox shader. it involved mapping the celestial sphere to a quad and doing a bunch of star rendering. sure. but while i was doing that i ended up having to confront some annoying properties of planetary space, namely, that the planet is a sphere. so the celestial sphere is a sphere, and different parts of it are visible at different locations at different times. so my shader ended up having a uniform for where on the planet you are. which, sure, reasonable. but that got me thinking about the process of actually travelling across a planet. this is kind of a classic problem, right? b/c spheres don't really map easily to data structures. there's a reason why every videogame world map is a flat rectangle, b/c spheres are connected together weirdly.
amitp has a little demo of one of the primary problems of spheres. whoops either you figure out how to distort stuff, or you have these unapproachable 'corners' of the map where reality breaks down. the stereographic projection is me going "well, let's see how you can distort stuff".namely, the use-case i'm thinking about involves walking around on the surface of a planet (not flying in orbit or digging to the core), and it involves (hopefully) a big planet, something where you can't just represent every point on the planet as 'distance from the center of the planet' and still end up with good fidelity at the surface (i think astroneer's planets, while quite big, are all still small enough to be stored directly as distance-from-core points). one of the major things i wanted to maintain was having the y axis as 'global up', even though... there's no such thing on a planet. because it's round. so a mapping from a sphere to a plane seems like a good candidate for something.
so, theoretically i could have some kind of graph-based setup for the actual world geometry, whether that's a cube or a rhombic dodecahedron or a collection of triangles with linked edges or w/e, and store them as 'flat surfaces' with edge connections, and then when rendering them i'd convert the points to 3d and then flatten them. this is the part i'm least confident of, since if i convert them to full 3d then this is the classic floating-point-precision-loss example: having two small numbers that you add a huge number to and then subtract out the same huge number later. but assuming that works, then you get some easily-storable data structure for your heightmap points (or w/e), and a projection that can use those points (albeit with some distortion).
what i actually did:
- sphere render
- i remembered how to render a point sphere. if you look in the source there is code to make any size/fidelity point sphere
- a stereographic projection of those points
- currently fixed to the 'north pole' but i think what i've written is a fully-general stereographic projection function, so it should be possible to use any point for the 'pole' and have the projection plane fixed to be perpendicular to that on the opposite side of the planet
- projection with lines
the other things i would've done if i had kept working on this:
- make it so you can actually 'drive' around the planet and spin the projection correspondingly
- actually make this into triangles so you can see, uh, an actual plane landscape here, instead of a dizzying point cloud
- redo all of this in webgl so it's all done in-shader, in a vertex shader
- write the inverse transformation so you can start with a point in the projection and get back the relevant point on the sphere, which would make all the smooth curves actually show up in the projection (and also solve the problem where the pole point turns into a point infinitely far away in every direction. that's projective geometry for you!!)
- figure out how to do this on a planet-scale planet (this is the big one obviously)
i just have these dreams of making a planet that's 1:1 scale of the earth that you can walk anywhere on and have an accurate celestial sphere above.