0

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 または色の入力を配置すると、結果が破損するのはなぜですか? 順序は重要ではありません。

4

1 に答える 1

0

これは、データをシェーダーに渡すときに使用する順序によるものです。OpenGL C または C++ コードでは、確かに頂点カラーを最初の頂点属性として送信し、次に位置を送信します。シェーダーでパラメーターの順序を入れ替える場合は、初期化の順序も入れ替える必要があります。

于 2013-02-22T10:24:32.867 に答える