我正在使用一个传递几个不同元素的缓冲区,下面是每个元素在缓冲区中出现的粗略图表:
pos col amb dif spe nor uv t a s
+---+---+---+---+---+---+--+-+-+-+
0 3 6 9 1 1 1 2 2 2 2
2 5 8 0 1 2 3
其中
pos - the vertex (3 floats)
col - the color at that vertex (note, this is a legacy variable that is unused(3 floats)
amb - the ambient RGB reflection of the model (3 floats)
dif - the diffuse RGB reflection of the model (3 floats)
spe - the specular RGB reflection of the model (3 floats)
nor - the normals of the model (3 floats)
uv - the uv coordinates to the mapped texture (2 floats)
t - a pointer to which texture to load (a float)
a - the transparency (alpha) of the model (a float)
s - the specular exponent (a float)
我的缓冲区看起来像这样:
// stride = how many floats to skip each round (times 4)
stride = 23 * 4;
// Last parameter = where this attribute starts in the buffer
GL.vertexAttribPointer(_position, 3, GL.FLOAT, false, stride, 0 * 4) ;
GL.vertexAttribPointer(_color, 3, GL.FLOAT, false, stride, 3 * 4) ;
GL.vertexAttribPointer(_ambient, 3, GL.FLOAT, false, stride, 6 * 4) ;
GL.vertexAttribPointer(_diffuse, 3, GL.FLOAT, false, stride, 9 * 4) ;
GL.vertexAttribPointer(_specular, 3, GL.FLOAT, false, stride, 12 * 4) ;
GL.vertexAttribPointer(_normals, 3, GL.FLOAT, false, stride, 15 * 4) ;
GL.vertexAttribPointer(_uvs, 2, GL.FLOAT, false, stride, 18 * 4) ;
GL.vertexAttribPointer(_tex, 1, GL.FLOAT, false, stride, 20 * 4) ;
GL.vertexAttribPointer(_a, 1, GL.FLOAT, false, stride, 21 * 4) ;
GL.vertexAttribPointer(_shine, 1, GL.FLOAT, false, stride, 22 * 4) ;
所有三个浮点数在顶点着色器中以相同的方式传递:
attribute float tex;
attribute float a;
attribute float shine;
...
varying float vTex;
varying float vA;
varying float vShine;
void main(void) {
...
vTex = tex;
vA = a;
vShine = shine;
我传递一切正常,直接复制/粘贴_tex
和_a
的{{1}}代码。没有错误弹出,如果我打印包含所有这些值的数组,一切都正确存储。同样,_shine
正在片段着色器中使用而没有错误。
_tex
第二个我转到void main(void) {
vec4 texColor;
//Ambient
vec4 Ia = La * Ka;
// Diffuse
vec4 Id = Kd;
vec3 lightDirection = normalize(world_light - vertex);
vec3 L = normalize(lightDirection - world_pos);
vec3 N = normalize(world_norm);
float lambert = max(0.0, dot(N, -L));
Id = Kd*Ld*lambert;
// Specular
vec4 Is = Ks;
vec3 V = normalize(vertex - world_pos);
vec3 H = normalize(L + V);
float NdotH = dot(N, H);
NdotH = max(NdotH, 0.0);
NdotH = pow(NdotH, 10.0);
// NdotH = pow(NdotH, vShine); <-------------------------------- ERRORS
Is = Ks*Ls*NdotH;
if (vTex < 0.1) {
vec4 texColor = texture2D(texture01, vUV);
gl_FragColor = vec4(texColor.rgb, texColor.a);
} else if (vTex < 1.1) {
vec4 texColor = texture2D(texture02, vUV);
gl_FragColor = vec4(texColor.rgb, texColor.a);
} else if (vTex < 2.1) {
vec4 texColor = texture2D(texture03, vUV);
gl_FragColor = vec4(texColor.rgb, texColor.a);
} else {
vec4 texColor = texture2D(texture04, vUV);
gl_FragColor = vec4(texColor.rgb, texColor.a);
}
gl_FragColor = gl_FragColor * (Ia*A) + (Id*D) + (Is*S);
,Chrome的WebGL将崩溃并显示以下错误消息:
NdotH = pow(NdotH, vShine);
这显然是令人困惑的部分,因为花车是属性,而不是制服。再一次,在Firefox中加载很好,但我试图了解Chrome前端的问题是什么,以及解决方案是什么,而不必重构。
我对发布完整代码犹豫不决,因为这是一个课堂作业。
谢谢!
答案 0 :(得分:0)
所以我发现了这个问题,它特别限制了Chrome在Max Varying Vectors上限,通过这里发现:https://www.browserleaks.com/webgl
关于为什么Chrome无法处理事情的问题是我向许多不同的向量推送到单个缓冲区,而Firefox可以处理30个,Chrome只能处理9.因为我处于这个尖端,这就是我的错误即将到来的地方从