shaunlebron / flex-fov

intelligent defaults for displaying any FOV
GNU General Public License v3.0
49 stars 4 forks source link

Add more comments to flex.fs #5

Open jokoon opened 6 years ago

jokoon commented 6 years ago

Hello,

First I want to thank you from working on this, it's really fascinating work and I want to thank you for sharing it. I having eye-ing it for a long time now.

I'm very interested in using the pannini projection in my project (170 degrees seems like a sufficient result), and I'd like to better understand how that shader works.

I've read the small summary here http://shaunlebron.github.io/visualizing-projections/ and I understand how it works. In blinky you talk about lenses and globes, but I still don't understand the low level details and I cannot connect the theory from the practice and the shader code.

In http://shaunlebron.github.io/visualizing-projections/ you state that pannini == stereographic, yet you have different functions for stereographic and pannini (stereographic_inverse, stereographic_forward, and panini_forward, panini_ray).

Variable names are not always self-descriptive (dscr, c, clon, S).

I guess I should start to use some paper and draw better geometry diagrams?

Your work would be much more valuable if you took a slight amount of time adding more comments about that code and its math. Sorry about asking to take time from your own!

shaunlebron commented 6 years ago

Hey thanks for your interest :)

However simple the projection, the math always comes out not really retaining that simplicity at a glance. Some projections I understood, but there were a ton of projections I was trying out without understanding how to derive them (I just pulled them from wikipedia and other projection libraries). Sometimes the math is impenetrable because they are by nature a compression of context that is hard to unpack. But the math isn't so important to understand as it is to learn how to apply them—via the forward/inverse coordinate mapping that I made sure was documented well here:

https://github.com/shaunlebron/blinky/tree/master/game/lua-scripts/lenses#lenses

If you are still interested in the math, the panini paper shows how it is derived:

screen shot 2018-08-26 at 12 56 57 pm

So that's where the variable names came from:

The stereographic projection math is on wikipedia.

Regarding the equivalence of Panini and Stereographic, they are only equivalent in 2D (in the top-down diagrams). To clarify, both projection methods do the same thing shown below—but Panini does it for a cylinder, and Stereographic does it for a sphere. And if you take a horizontal slice at the center of a sphere and a cylinder, both slices are equal to the same circle, which is why they're equivalent in 2D, but they're formulas are different in 3D.

screen shot 2018-08-26 at 1 06 33 pm
jokoon commented 6 years ago

Woa thanks for the reply, that's quite helpful :)

Other question: in blinky, why does changing projection is often slow, it's calculating pixel by pixel when loading one or another projection?

Regards,

Jonas

On Sun, Aug 26, 2018 at 8:17 PM Shaun Lebron notifications@github.com wrote:

Hey thanks for your interest :)

However simple the projection, the math always comes out not really retaining that simplicity at a glance. Some projections I understood, but there were a ton of projections I was trying out without understanding how to derive them (I just pulled them from wikipedia and other projection libraries). Sometimes the math is impenetrable because they are by nature a compression of context that is hard to unpack. But the math isn't so important to understand as it is to learn how to apply them—via the forward/inverse coordinate mapping that I made sure was documented well here:

https://github.com/shaunlebron/blinky/tree/master/game/lua-scripts/lenses#lenses

If you are still interested in the math, the panini paper http://tksharpless.net/vedutismo/Pannini/panini.pdf shows how it is derived:

[image: screen shot 2018-08-26 at 12 56 57 pm] https://user-images.githubusercontent.com/116838/44631329-e6784980-a92f-11e8-96ff-021076a7f4ae.png

So that's where the variable names came from:

  • dscr = discriminant
  • clon = cosine of longitude
  • S = (not mnemonic)

The stereographic projection math is on wikipedia.

Regarding the equivalence of Panini and Stereographic, they are only equivalent in 2D (in the top-down diagrams). To clarify, both projection methods do the same thing shown below—but Panini does it for a cylinder, and Stereographic does it for a sphere. And if you take a horizontal slice at the center of a sphere and a cylinder, both slices are equal to the same circle, which is why they're equivalent in 2D, but they're formulas are different in 3D.

[image: screen shot 2018-08-26 at 1 06 33 pm] https://user-images.githubusercontent.com/116838/44631440-13792c00-a931-11e8-8249-de63f6237447.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/shaunlebron/flex-fov/issues/5#issuecomment-416058112, or mute the thread https://github.com/notifications/unsubscribe-auth/AAglbdZ0GHzvCOlNXyIMoX35iD6J5ZRmks5uUuZRgaJpZM4WLUZ6 .

shaunlebron commented 6 years ago

blinky computes a lookup table that maps a pixel on the screen to a pixel on the globe, and that takes time. Fun fact—computing them used to freeze the game for a 2-3 seconds, so I opted to compute them little by little in each frame (i.e. scanlines from bottom to top) so the player could run around while the projection is being computed. The alternative is to pre-compute the lookup tables for each projection and resolution and store them in files, which I never did.

Shaders on the GPU are built specifically to run a function for each pixel in parallel, so lookup tables don't need to be computed, you just write a shader and it's all very fast. That's why flex-fov is much faster and facilitated me trying new things like combining projections to see what it looked like.

jokoon commented 6 years ago

Another question:

I'm comparing mercator with pannini with same FOV, and it has the advantage of having "larger" zoom near the center of the screen, meaning geometry is occupying more pixels near the center.

I'm wondering if I could somehow try to have similar results with the pannini projection by changing globe values in the globe folder? It seem that not, but I'm still thinking about thinking of a way to do this.

My goal is to have less geometry for more pixel near the center, to have a good impression of what is at a distance, but still have a large field of view. Maybe what I want is an elliptical cylinder, but I doubt that the math for that is available.

I tried changing d in pannini.lua to 2, I guess it is the distance of the second camera to the center, and it somehow did what I want, I joined a screenshot of the rubix and the render to "compress" geometry that is near the edges of the screen.

Where does the gumby projection comes from? I could not find it there https://en.wikipedia.org/wiki/List_of_map_projections The math looks like it's pannini.

I've seen your flex and mc360, but I have not had the chance to test them yet. I admit I would like to implement this projection in a C++ with opengl, but I'm not very fluent in shading languages combined with opengl.

What do you mean by "not mnemonic" ?

Jonas

On Mon, Aug 27, 2018 at 3:45 PM Jonas O. ezjonas@gmail.com wrote:

Woa thanks for the reply, that's quite helpful :)

Other question: in blinky, why does changing projection is often slow, it's calculating pixel by pixel when loading one or another projection?

Regards,

Jonas

On Sun, Aug 26, 2018 at 8:17 PM Shaun Lebron notifications@github.com wrote:

Hey thanks for your interest :)

However simple the projection, the math always comes out not really retaining that simplicity at a glance. Some projections I understood, but there were a ton of projections I was trying out without understanding how to derive them (I just pulled them from wikipedia and other projection libraries). Sometimes the math is impenetrable because they are by nature a compression of context that is hard to unpack. But the math isn't so important to understand as it is to learn how to apply them—via the forward/inverse coordinate mapping that I made sure was documented well here:

https://github.com/shaunlebron/blinky/tree/master/game/lua-scripts/lenses#lenses

If you are still interested in the math, the panini paper http://tksharpless.net/vedutismo/Pannini/panini.pdf shows how it is derived:

[image: screen shot 2018-08-26 at 12 56 57 pm] https://user-images.githubusercontent.com/116838/44631329-e6784980-a92f-11e8-96ff-021076a7f4ae.png

So that's where the variable names came from:

  • dscr = discriminant
  • clon = cosine of longitude
  • S = (not mnemonic)

The stereographic projection math is on wikipedia.

Regarding the equivalence of Panini and Stereographic, they are only equivalent in 2D (in the top-down diagrams). To clarify, both projection methods do the same thing shown below—but Panini does it for a cylinder, and Stereographic does it for a sphere. And if you take a horizontal slice at the center of a sphere and a cylinder, both slices are equal to the same circle, which is why they're equivalent in 2D, but they're formulas are different in 3D.

[image: screen shot 2018-08-26 at 1 06 33 pm] https://user-images.githubusercontent.com/116838/44631440-13792c00-a931-11e8-8249-de63f6237447.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/shaunlebron/flex-fov/issues/5#issuecomment-416058112, or mute the thread https://github.com/notifications/unsubscribe-auth/AAglbdZ0GHzvCOlNXyIMoX35iD6J5ZRmks5uUuZRgaJpZM4WLUZ6 .

18107 commented 6 years ago

I found this but never had the time to implement it. https://youtu.be/oVwmF_vrZh0