Last active
March 14, 2023 15:21
-
-
Save fospathi/8227bb28e79d27379051cad82364c40c to your computer and use it in GitHub Desktop.
Revisions
-
fospathi revised this gist
Mar 14, 2023 . 1 changed file with 18 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,16 @@ # Aspect distortion of relative vectors composed in NDC space The distortion affects relative vectors calculated in NDC (OpenGL Normalised Device Coordinates) space at the point at which they are mapped to a rectangular (i.e. non-square) screen. Let the metric used to measure distance be the proportion of the height of the (NDC cube)/screen. Let's say we wish to calculate a position Q in NDC which is a desired distance from P on the screen. For a square screen, nothing needs to be done, just calculate PQ as normal. For a screen aspect ratio ≠ 1, e.g. when the screen width is greater than the screen height, the relative vector needs to be scaled in the X-axis direction. Q Q' | / / @@ -19,10 +20,13 @@ needs to be scaled in the X-axis direction. P/P'_/_ _ _ _ _ _ _ _ _ _ | For a square aspect ratio, Q = Q'. The process that stops the distortion: 1. calculate the relative vector PQ' with the desired length; 2. scale PQ' in the X-axis direction by `1/(aspect ratio)` giving PQ; 3. add PQ to P to get Q. The X-axis scaling from step 2 is ultimately undone by the NDC to screen space transformation applied by OpenGL. -
fospathi revised this gist
May 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Consider a point P in OpenGL Normalised Device Coordinates (NDC). Let's say we w position Q (with images P' and Q' after the screen space transformation) in NDC such that the vector P'Q' maintains a constant screen space proportion of screen height. For a square aspect ratio nothing needs to be changed, just calculate PQ as normal. For an aspect ratio > 1, i.e. where the screen width is greater than the screen height, PQ needs to be scaled in the X-axis direction. Q Q' | / / -
fospathi revised this gist
May 27, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,6 @@ needs to be scaled in the X-axis direction so that P'Q' maintains a constant pro The process that stops the distortion: 1. Calculate the relative vector PQ as normal as though a square aspect ratio was in place. 2. Scale PQ in the X-axis direction by `1/(aspect ratio)`. 3. Add PQ to P to get Q. 4. The X-axis scaling from step 2 is ultimately undone by the NDC to screen space transformation applied by OpenGL. -
fospathi revised this gist
May 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ (:pushpin: NDC means OpenGL Normalised Device Coordinates.) # Aspect distortion of relative vectors composed in NDC space The distortion affects relative vectors calculated in NDC space when the NDC to screen space transformation is applied. The distortion occurs because a square/NDC cube is being mapped to a screen rectangle. -
fospathi created this gist
May 27, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ (:pushpin: NDC means OpenGL Normalised Device Coordinates.) #Aspect distortion of relative vectors composed in NDC space The distortion affects relative vectors calculated in NDC space when the NDC to screen space transformation is applied. The distortion occurs because a square/NDC cube is being mapped to a screen rectangle. Consider a point P in OpenGL Normalised Device Coordinates (NDC). Let's say we wish to calculate a relative-to-P position Q (with images P' and Q' after the screen space transformation) in NDC such that the vector P'Q' maintains a constant screen space proportion of screen height. For a square aspect ratio nothing needs to be changed, just calculate PQ as normal. For an aspect ratio > 1, i.e. where the screen width is greater than the screen height, PQ needs to be scaled in the X-axis direction so that P'Q' maintains a constant proportion of screen height. Q Q' | / / | / / | / / | / / P/P'_/_ _ _ _ _ _ _ _ _ _ | For a square aspect ratio Q = Q'. The process that stops the distortion: 1. Calculate the relative vector PQ as normal as though a square aspect ratio was in place. 2. Scale PQ in the X-axis direction by 1/(aspect ratio). 3. Add PQ to P to get Q. 4. The X scaling from step 2 is ultimately undone by the NDC to screen space transformation applied by OpenGL.