这个顶点着色器在做什么?
What is this vertex shader doing?
我最近接手了一个停滞不前的项目,一个团队成员几个月前辞职了。当我试图让自己加快速度时,我遇到了这个顶点着色器,我很难理解它在做什么:
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;
我似乎找不到解释这个的文档。
谁能给一个快速的解释这个着色器是做什么?
我似乎找不到解释这个的文档。
GLSL规范非常清楚swizzle选择是如何工作的。
着色器所做的基本上是一种从vec4
中选取两个轴的钝化方式。注意,point
的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);
所以它只是从输入顶点中选择两个坐标。我不知道为什么它需要这样做。
x, y, z和w的顺序。确定从gl_Vertex的x, y, z, w到point的x, y, z, w的映射。
这叫做搅拌。point = gl_Vertex
等于point = gl_Vertex.xyzw
。point = gl_Vertex.yxzw
的结果相当于gl_Vertex的x和y值交换。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 如何循环打印顶点结构
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- 使用此网格函数的立方体的正确顶点和索引是什么
- DirectX:如果绑定索引缓冲区但不绑定顶点缓冲区,会发生什么情况
- 在现有数据结构上使用BGL算法需要什么(边和顶点作为矢量<对象*>)?
- 在 OpenGL 中,在保持良好帧速率的同时,VBO 中有多少个顶点的好目标是什么
- 在版本 440 核心中绘制具有纹理的立方体的顶点和片段着色器应该是什么
- 顶点属性大小不匹配时会发生什么情况
- GLMmodel 顶点中的 -431602080.000000 值是什么意思
- 自定义顶点处理器不起作用 - 矩阵乘法错误或其他什么?
- 提升图库中的顶点描述符和索引有什么区别?
- Android Open GL ES 2.0 -顶点数组对象(VAO)的要求是什么?
- 语义和顶点布局在D3D11中的意义是什么?
- 这个顶点着色器在做什么?
- 这段代码中的顶点和纹理坐标代表什么?
- OpenGL如何知道它应该基于GL_ARRAY_BUFFER绘制顶点到什么位置
- 提升图:在度数为 0 的顶点上调用remove_vertex时会发生什么>
- 寻找遍历图中所有顶点的路径的更好算法是什么?