難道是更快的WebGL來呈現多重紋理一通,如:渲染多重紋理在一個着色器通道
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倍的程序調用更快,我已經讀過,即使在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必須做多少?