次のように、WebGL で複数のテクスチャを 1 つのパスでレンダリングする方が高速でしょうか。
varying float materialIndex;
varying vec2 textureCoord;
uniform sampler2D textureSampler1;
uniform sampler2D textureSampler2;
uniform sampler2D textureSampler3;
uniform sampler2D textureSampler4;
vec4 getMaterial(float materialId, textureCoord) {
vec4 color;
if (materialId == 1.0)
{
color = texture2D( textureSampler1, textureCoord );
}
else if (materialId == 2.0)
{
color = texture2D( textureSampler2, textureCoord );
}
else if (materialId == 3.0)
{
color = texture2D( textureSampler3, textureCoord );
}
else
{
color = texture2D( textureSampler4, textureCoord );
}
return color;
}
void main()
{
vec4 color = getMaterial(materialIndex, textureCoord);
gl_FragColor = color;
}
これにより、CPU が GPU に送信する必要がある命令の 4 分の 1 を節約できるため、頂点シェーダーが渡す必要のある追加の情報に加えて、多くの場合、4 倍のプログラム呼び出しを行うよりも高速ではないでしょうか。 OpenGL でさえ、最大のパフォーマンス ヒットは CPU であると読んだことがありますが、これは Webgl の場合にさらに当てはまります。それとも、これはおそらくより速いでしょうか?
uniform float materialIndex;
varying vec2 textureCoord;
uniform sampler2D textureSampler1;
uniform sampler2D textureSampler2;
uniform sampler2D textureSampler3;
uniform sampler2D textureSampler4;
void main()
{
vec4 color = getMaterial(materialIndex, textureCoord);
gl_FragColor = color;
}
それとも、機能的なユニフォームを変更することは、CPU が実行しなければならない呼び出しの数に関して、新しいシェーダーをロードすることと同じくらい悪いことですか?