0
glDrawArraysInstanced関数を使用して、三角形を二重にする必要があります。 2つの違いはMVPマトリックスです。 次に、2つのGL_COLOR_ATTACHMENTを持つFBOを適用し、glDrawBuffers(2、...)をアクティブにします。fragmentShaderでデータを出力するときにレイアウトの位置を切り替える
私頂点シェーダ:
#version 430 core
layout (location = 0) in vec3 position;
uniform mat4 uModel;
uniform mat4 uView[2];
uniform mat4 uProjection[2];
out flat int ID;
void main()
{
gl_Position = uProjection[gl_InstanceID] * uView[gl_InstanceID] * uModel * vec4(position.x, position.y, position.z, 1.0);
ID = gl_InstanceID;
}
私のフラグメントシェーダ:
#version 430 core
layout (location = 0) out vec3 color;
layout (location = 1) out vec3 color1;
in flat int ID;
void main()
{
if (ID == 0) color = vec3(1.0f, 0.5f, 0.2f);
if (ID == 1) color1 = vec3(1.0f, 0.0f, 0.0f);
}
結果は次のとおりです。 4 triangles..
各インスタンス化は、色を実装していたようだし、 color1ステートメント。 「if」ステートメントが無効なのでしょうか? 私の質問はfboと1回のパスの間に出力ターゲットがどれくらい制限されているかです。
IDが入力ではなく一様である場合は、書き込みマスクを使用して特定のバッファへの書き込みをオフにすることができます。 –
あなたの返事をありがとう、私は今それを試してみます。しかし、それは少し浪費のようです... –
新しい質問....あなたが言うように、シェイダーがすべての出力に書き込む場合は、同じ色の三角形で、 'オレンジ' '赤'と '赤' 'オレンジ'になります。したがって、 'if'ステートメントは無効ですか? –