OpenGL片段着色器如何知道纹理中要采样的像素?

a p*_*erd 5 shader opengl-es webgl vertex-shader fragment-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);
}
Run Code Online (Sandbox Code Playgroud)

我有一个片段着色器:

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

void main(void) {
  gl_FragColor = texture2D(uMyTexture, vTextureCoords);
}
Run Code Online (Sandbox Code Playgroud)

我提供了三组顶点和UV,交错:

# 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
Run Code Online (Sandbox Code Playgroud)

片段着色器如何知道以不同于像素B的方式绘制像素A?有什么变化?

gen*_*ult 7

据我所知,GL管道的光栅化阶段在三角形面上进行插值 ,在内插值vTextureCoords的每个像素上运行片段着色器.

  • 有关此答案以及动画的进一步说明,请访问:http://greggman.github.com/webgl-fundamentals/webgl/lessons/webgl-how-it-works.html (3认同)