Opengl 输入属性的顺序如何影响渲染结果?
交换两个输入变量的顺序会损坏渲染结果。为什么呢 关于其用法的小信息:Opengl 输入属性的顺序如何影响渲染结果?,opengl,glsl,Opengl,Glsl,交换两个输入变量的顺序会损坏渲染结果。为什么呢 关于其用法的小信息: #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 fragmentCol
#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;
}
- Vertu模型空间的位置为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;
}
错了:
#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;
}
#版本130
//输入顶点数据,此着色器的所有执行都不同。
在vec3\u模型空间中;// 这是因为将数据传递给着色器时使用的顺序。在你的OpenGL C或C++代码中,你肯定把顶点颜色作为第一顶点ATTILB发送,然后发送位置。如果要交换着色器中参数的顺序,也必须交换其初始化顺序。是。我绑定缓冲区并首先为位置(位置=0)设置指针,然后为颜色(位置=1)设置指针。为什么着色器中的顺序是相反的?@Miro:因为你没有强制编译器将它们放到特定的位置。使用layout(location=…)
存储限定符来确定它们。感谢您的回答。它为我指明了正确的方向。但这并不完全正确。问题是我在指定属性位置之前链接了程序。