Ivan Lugo
08/14/2022, 9:37 PMTony Cheal
08/14/2022, 9:54 PMIvan Lugo
08/14/2022, 10:10 PMKeywords: Texture / glyph atlas, macOS, Swift, Metal, iOS, vector space transforms
Given: I’ve got a set of “vertices” (x, y) in normalized space, from (-1, 1) on the domain and range. Just a simple cartesian space. I’ve also got a set of “texture coordinates” (u, v), which instead map to (0, 1) on the domain and range, with (0, 1) on the range an x-axis flip. This is apparently really common, and it’s the way the Metal shading language defines its coordinate spaces.
I also know how to convert from vertex-space to uv-space:
u = (x + 1) / 2
v = -(y - 1) / 2
Also given: I have a texture in UV space where I want to define arbitrary rectangles. These rectangles are glyph-stamps in the [(0,1), (0,1)] bounding box range. These are easily computed given the full size of the texture I am creating rectangles from.
The problem: I have a single set of vertices that define a quad. Top left / right, bottom left / right. These are always centered around the origin. Meaning, I can have a square that fills the vector space with these coordinates:
(-1, 1)
(-1, -1)
( 1, 1)
( 1, -1)
Assume we will “resize” those in some way by symmetrically bringing in the sides as needed - again, all around the origin.
Given that I have those precomputed coordinates above which map to UV space, how do I take those arbitrary vertices in vertex space and map them to the ‘rectangular sections’ of uv-space?Tony Cheal
08/14/2022, 10:38 PMIvan Lugo
08/14/2022, 10:43 PMTony Cheal
08/14/2022, 11:15 PMIvan Lugo
08/14/2022, 11:16 PMRobin
08/15/2022, 12:06 AMIvan Lugo
08/15/2022, 12:16 AMRobin
08/15/2022, 1:56 AMIvan Lugo
08/15/2022, 2:11 AMKartik Agaram
Ivan Lugo
08/15/2022, 2:47 AMTom Larkworthy
08/15/2022, 5:45 AMIvan Lugo
08/15/2022, 4:23 PMKartik Agaram
Duncan Cragg
08/19/2022, 10:05 PM