0
交换两个输入变量的顺序会破坏渲染结果。这是为什么?输入属性的顺序如何影响渲染结果?
关于它的一点信息的使用:
- vertexPosition_modelspace具有位置0和顶点颜色具有位置1
- 我绑定缓冲存储顶点位置,并设置顶点ATTRIB指针,然后我绑定,并设置缓冲区颜色
正确的:
#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或颜色输入,为什么结果会损坏?订单不应该紧。
是的。我绑定缓冲区并为位置先设置指针(位置= 0),然后设置颜色(位置= 1)。为什么在着色器中的顺序相反? – kravemir 2013-02-22 10:27:40
@Miro:因为你没有强制编译器将它们放到特定的位置。使用'布局(位置= ...)'存储限定符来固定它们。 – datenwolf 2013-02-22 10:32:18
感谢您的回答。它以正确的方式指出了我。但这并不完全正确。在指定attrib位置之前,问题是我链接的程序。 – kravemir 2013-02-22 10:41:13