To introduce things out.

Space can be represented by a sphere, like a Google Street View, where 360 degree image is wrapped on a sphere and seen form inside.

To grab a portion of 3D space (sphere) and display it on a flat surface, like a monitor we have to map its coordinates on flat UV space.

Basically whole topic of map projections is about displaying sphere (world map) or its portion (e.g. city map) on a flat plane.

What we want to achieve here is mapping scaled Stereographic screen coordinates onto Linear image coordinates, since we are using game-texture UV-space lookup.

It has to be scaled at first since we want to adjust the borders size, and scaling (zooming) will change Stereographic screen FOV at the borders of the image.

Simple UV multiply changes the distortion.

Linear projection in cartography is Gnomonic projection.

And difference between linear projection and stereographic projection is simple point of view.

Linear projection looks from the center of the sphere:

Stereographic projection looks from the surface of the sphere:

Drawing shows flat view from above on the camera frustum.

Even doe it's 2D shader, we operate in 3D space and

only things that we know is UV position of current pixel being processed and in-game camera FOV which user enters in shader settings. That's 2D data, UV = XY, to get the third component Z (XYZ) we can use cotangent of 1/4 FOV.

To get the linear pixel coordinates, we "project" the point onto a sphere surface, then we "look at it" from the sphere center and finally we scale it down to the crosing of the image plane (projection plane).

Now if we scale (zoom) the final image, we also need to scale the Z component, or C component.

The

**[?=x'/x]** is the thing by which we multiply the radial UV coordinates of the game texture.

One can ask, "if it's all cartography, why won't we use already existing formulas!" Well, they're all based on latitude and longitude coordinates which require a lot of trigonometry. We want to avoid that.

It's manageable through similar triangles, etc.

I haven't figure everything out yet, but I'll try. Optimistically I will be able to get new formula in few days, but if you do it faster, feel free.