我正在尝试构建一个着色器(在glsl 1.0中),它使用sampler2d纹理数组和samplerCube纹理数组。奇怪的是,如果我交替使用两个纹理,我无法链接它(我无法得到错误信息)。通过试验和错误,我找到了导致问题的代码:
这无法编译:
varying highp vec2 vTextureCoord;
varying highp vec2 vTextureCoord2;
varying lowp vec3 vLighting;
varying lowp vec4 vColor;
varying lowp vec3 vNormal;
#ifdef Textures\r\n"
uniform sampler2D uSampler[Textures];
uniform lowp vec2 texFlag[Textures];
uniform lowp mat3 texMat[Textures];
uniform lowp float tex_coord_set[Textures];
uniform samplerCube uSamplerC[Textures];
#endif
uniform lowp vec3 fogColor;
varying lowp float fogBlend;
void main(void) {
#ifdef Textures
mediump vec4 pixColor = vColor;
mediump vec3 SpecNormal = reflect(vec3(0.0,0.0,1.0), vNormal);
mediump vec4 texelColor;
pixColor += textureCube(uSamplerC[0], vNormal);
pixColor += texture2D(uSampler[0], vec2(0.0,0.0));
pixColor += textureCube(uSamplerC[1], vNormal);
pixColor += texture2D(uSampler[1], vec2(0.0,0.0));
else
mediump vec4 pixColor = vColor;
#endif
但如果我说:
pixColor += textureCube(uSamplerC[0], vNormal);
pixColor += textureCube(uSamplerC[1], vNormal);
pixColor += texture2D(uSampler[0], vec2(0.0,0.0));
pixColor += texture2D(uSampler[1], vec2(0.0,0.0));
(首先是一种类型的所有采样器)它似乎完美地连接起来。为什么呢?
(注意:此代码,目前的形式,毫无意义,我只用它来揭露问题)