我发现在我的片段着色器中,这两个语句给出了相同的输出:
// #1
// pos is set from gl_Position in vertex shader
highp vec2 texc = ((pos.xy / pos.w) + 1.0) / 2.0;
// #2 - equivalent?
highp vec2 texc2 = gl_FragCoord.xy/uWinDims.xy;
如果这是正确的,你能解释一下数学吗?我理解#2,这是我想出的,但在一篇论文中看到了#1。这是 NDC(标准化设备坐标)计算吗?
上下文是我正在使用与视口大小相同的 FBO 纹理坐标。一切正常,但我想了解数学。
顶点着色器的相关部分:
attribute vec4 position;
uniform mat4 modelViewProjectionMatrix;
varying lowp vec4 vColor;
// transformed position
varying highp vec4 pos;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
// for fragment shader
pos = gl_Position;
vColor = aColor;
}
片段着色器的相关部分:
// transformed position - from vsh
varying highp vec4 pos;
// viewport dimensions
uniform highp vec2 uWinDims;
void main()
{
highp vec2 texc = ((pos.xy / pos.w) + 1.0) / 2.0;
// equivalent?
highp vec2 texc2 = gl_FragCoord.xy/uWinDims.xy;
...
}