难道是更快的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必须做多少?