How do the shaders of OpenGL fragments know which pixel for the sample in the texture?

So I have a triangle:

And I have a vertex shader:

uniform mat4 uViewProjection;
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoords;
varying vec2 vTextureCoords;

void main(void) {
  vTextureCoords = aTextureCoords;
  gl_Position = uViewProjection * vec4(aVertexPosition, 1.0);
}

And I have a fragmented shader:

precision mediump float;
uniform sampler2D uMyTexture;
varying vec2 vTextureCoords;

void main(void) {
  gl_FragColor = texture2D(uMyTexture, vTextureCoords);
}

And I feed on three sets of vertices and UVs alternating:

# x,  y,    z,   s,   t
0.0,  1.0,  0.0, 0.5, 1.0
-1.0, -1.0, 0.0, 0.0, 0.0 
1.0, -1.0,  0.0, 1.0, 0.0

As it is known to the fragment shader, to draw pixel A differently than pixel B? Which changes?

+5
source share
1 answer

As I understand it, the rasterization step of the GL pipeline interpolates vTextureCoords through the edge of the triangle, starting the fragment shader on each pixel with an interpolated value.

+7
source

All Articles