You donβt need to do any special math if you just pass the vertex interpolate coordinate from the vertex shader.
For example, if you draw a simple square of the unit that covered your screen, you could simply and then get a full-screen texture, you could just do something like this:
vertex shader pseudocode: layout(position = 0) in vec3 in_vertex; out vec3 out_vertex; void main() {
Your vertex shader will correctly interpolate in_vertex to the range x: 0 ... 1, y: 0 ... 1 (while you are drawing a unit square) and pass it to the shader fragment. Then your fragment shader will use it like this:
fragment shader pseudocode: in vec3 out_vertex; uniform sampler2D tex; void main() { gl_fragcolor = texture(tex,vec2(out_vertex.x,out_vertex.y)); }
No other math is required if you make sure that out_vertex is always in the range 0 ... 1. To expand this example a bit, imagine our area:
(0,1)+-----------+(1,1) | | | | | | | | | | (0,0)+-----------+(0,1)
And we wanted to try this point in the exact center:
(0,1)+-----------+(1,1) | | | | | * | | | | | (0,0)+-----------+(0,1)
Our vertex shader will automatically interpolate this position from the other 4 positions and transfer the following vec3 to the fragment shader:
out_vertex = vec3(0.5,0.5,0);
which can then be used to successfully select a texture