【问题标题】:How do OpenGL fragment shaders know what pixel to sample in a texture?OpenGL 片段着色器如何知道要在纹理中采样的像素?
【发布时间】:2013-01-31 18:50:33
【问题描述】:

所以我有一个三角形:

我有一个顶点着色器:

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

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

我有一个片段着色器:

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

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

我输入三组顶点和 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

片段着色器如何知道绘制像素 A 与像素 B 不同?有什么变化?

【问题讨论】:

  • 你喂的纹理对吗?为什么您希望它们是相同的,或者您是在问着色器如何在 GPU 上工作?
  • @JesusRamos 我在问着色器是如何工作的。我不明白在着色器通道之间发生了什么变化以及是谁在改变它。
  • 查看@genpfault 的答案。我本来想说同样的话,但他打败了我:)
  • 检查这个很好的答案stackoverflow.com/q/14246604/187752,当 OpenGL 可能会采样您不期望的值时。

标签: opengl-es webgl shader fragment-shader vertex-shader


【解决方案1】:

据我了解,GL 管道interpolatesvTextureCoords 的光栅化阶段横跨三角形面,使用插值在每个像素上运行片段着色器。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多