I'm rendering a full screen quad using gl_VertexID
as GL_TRIANGLE_STRIP
const vec2 kVertices[4] = vec2[]
(
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0)
);
void main() {
gl_Position = vec4(kVertices[gl_VertexID], 1.0, 1.0);
vs_out.texCoords = gl_Position.xy / 2.0 + 0.5;
vs_out.instanceID = gl_InstanceID;
}
Geometry shader just passes coordinates through into the output called vTexCoords
.
Then, in fragment shader, I output red and green into 2x2 texture using following code:
if (vTexCoords.x >= 0.95) {
oFragData0 = vec4(0.0, 1.0, 0.0, 1.0);
} else {
oFragData0 = vec4(1.0, 0.0, 0.0, 1.0);
}
I always assumed texture coordinates (0; 0), (0; 1), (1; 0), (1; 1) would map to the vertices, but the output is completely red, which means X value never reaches 1.0.
Then I'm trying to use 0.75 (vTexCoords.x >= 0.75
), which is a texel center, and half of the texture becomes green, as expected.
What am I misunderstanding here?