Doubts about shaders and renderTextures

Doubts about shaders and renderTextures
0.0 0



I need to render some primitives into a full screen RenderTexture.

I’m calculating the texture coordinates of each texel of the primitives as gl_FragPos/TextureSize, but this approach is slowly and I would like to calculate these coordinates in the vertex shader if this is possible and interpolate them as a varying in the fragment shader.

I would like to calculate the vertex coordinates as a texture coordinates of the RenderTexture. That is, if a vertex is in the center of the RenderTexture the transformed coordinates would be (0.5, 0.5), so these coordinates vary from 0 to 1 in the corners of the texture.

How can I get these values? could be:

texCoor = a_position / textureSize

Or Should I use the gl_Position projected value?
Something like:

vec4 p = modelView * a_position ; // transform vertex position with modelview matrix
gl_Position = projection * p; // project the transformed position and write it to

texCoor = gl_Position * 0.5 + 0.5;

Would I need to invert the y coordinate? (I’ve seen this before, but I have no idea when it is neccesary). I think that the lower left screen pixel has the vertex coords(0, 0) and the uvs(0, 0) and the top right one has the vertex coords(screenSize.width, ScreenSize.height) and uvs(1, 1). Is this right?

Thanks in advance