2 つの入力変数の順序を入れ替えると、レンダリング結果が破損します。何故ですか?
その使用法に関する小さな情報:
- 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 にもあり、問題を発見するのに 1 時間かかりました。位置の後に texcoord または色の入力を配置すると、結果が破損するのはなぜですか? 順序は重要ではありません。