Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Add more comments to flex.fs #5

Open
jokoon opened this issue Aug 24, 2018 · 5 comments
Open

Add more comments to flex.fs #5

jokoon opened this issue Aug 24, 2018 · 5 comments

Comments

@jokoon
Copy link

jokoon commented Aug 24, 2018

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
Copy link
Owner

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:

  • 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.

screen shot 2018-08-26 at 1 06 33 pm

@jokoon
Copy link
Author

jokoon commented Aug 27, 2018 via email

@shaunlebron
Copy link
Owner

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
Copy link
Author

jokoon commented Aug 27, 2018 via email

@18107
Copy link
Collaborator

18107 commented Aug 27, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants