两个输入变量的交换顺序会破坏渲染结果。这是为什么?
关于它的使用的小信息:
- vertexPosition_modelspace 的位置为 0,vertexColor 的位置为 1
- 我绑定存储顶点位置的缓冲区并设置顶点属性指针,然后绑定并设置缓冲区的颜色
正确的那一个:
#version 130
// Input vertex data, different for all executions of this shader.
in vec3 vertexColor;
in vec3 vertexPosition_modelspace;
// Output data ; will be interpolated for each fragment.
out vec3 fragmentColor;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
// The color of each vertex will be interpolated
// to produce the color of each fragment
fragmentColor = vertexColor;
}
错误一:
#version 130
// Input vertex data, different for all executions of this shader.
in vec3 vertexPosition_modelspace; // <-- These are swapped.
in vec3 vertexColor; // <--
// Output data ; will be interpolated for each fragment.
out vec3 fragmentColor;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
// The color of each vertex will be interpolated
// to produce the color of each fragment
fragmentColor = vertexColor;
}
texcoords 也有同样的问题,我花了一个小时才发现问题。如果我在位置之后放置 texcoord 或颜色输入,为什么结果会损坏?顺序应该无关紧要。