我最近接手了一个项目,该项目停滞不前,一名团队成员几个月前退出了。在努力让自己跟上速度的过程中,我遇到了这个顶点着色器,但我很难理解它在做什么:
uniform int axes;
varying vec4 passcolor;
void main()
{
// transform the vertex
vec4 point;
if (axes == 0) {
point = gl_Vertex;
} else if (axes == 1) {
point = gl_Vertex.xzyw;
} else if (axes == 2) {
point = gl_Vertex.xwzy;
} else if (axes == 3) {
point = gl_Vertex.yzxw;
} else if (axes == 4) {
point = gl_Vertex.ywxz;
} else if (axes == 5) {
point = gl_Vertex.zwxy;
}
point.z = 0.0;
point.w = 1.0;
// eliminate w point
gl_Position = gl_ModelViewProjectionMatrix * point;
passcolor = gl_Color;
}
我想更好地理解的行是这样的行:
point = gl_Vertex.xwzy;
我似乎找不到解释这一点的文档。
谁能快速解释一下这个着色器在做什么?
最佳答案
I can't seem to find documentation that explains this.
GLSL specification很清楚如何swizzle selection有效。
着色器基本上做的是一种从 vec4
中选取两个轴的钝化方法。请注意,点
的 Z 和 W 在选择后被覆盖。无论如何,它可以重写为:
vec2 point;
if (axes == 0) {
point = gl_Vertex.xy;
} else if (axes == 1) {
point = gl_Vertex.xz;
} else if (axes == 2) {
point = gl_Vertex.xw;
} else if (axes == 3) {
point = gl_Vertex.yz;
} else if (axes == 4) {
point = gl_Vertex.yw;
} else if (axes == 5) {
point = gl_Vertex.zw;
}
gl_Position = gl_ModelViewProjectionMatrix * vec4(point.xy, 0.0, 1.0);
所以它只是从输入顶点中选择两个坐标。为什么需要这样做,我不能说。
关于c++ - 这个顶点着色器在做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7669680/