**更新** - 我刚检查它是否在Firefox中正常工作。确实如此。问题似乎与Chromium如何处理WebGL有关。再次,请参阅下面的github链接。
我支持webgl / CV程序时,我注意到该网站开始从我没有触及的代码中发出错误。由于webgl程序未正确链接,因此抛出错误。我觉得这很奇怪,因为当我上次触及项目的这个特定方面(约2个月前)时它很好。一些研究向我指出了这个链接:Github discussion of the issue
根据我的理解(如果我错了请纠正我),有一个更新webgl如何处理不同类型变量的更新。我将发布着色器代码和使用它的函数,希望有人可以指出测试我没有的东西。
this.createProgramObject = function(vetexShaderSource, fragmentShaderSource) {
var vertexShaderObject = this.ctx.createShader(this.ctx.VERTEX_SHADER);
this.ctx.shaderSource(vertexShaderObject, vetexShaderSource);
this.ctx.compileShader(vertexShaderObject);
if (!this.ctx.getShaderParameter(vertexShaderObject, this.ctx.COMPILE_STATUS)) {
throw this.ctx.getShaderInfoLog(vertexShaderObject);
}
var fragmentShaderObject = this.ctx.createShader(this.ctx.FRAGMENT_SHADER);
this.ctx.shaderSource(fragmentShaderObject, fragmentShaderSource);
this.ctx.compileShader(fragmentShaderObject);
if (!this.ctx.getShaderParameter(fragmentShaderObject, this.ctx.COMPILE_STATUS)) {
throw this.ctx.getShaderInfoLog(fragmentShaderObject);
}
var programObject = this.ctx.createProgram();
this.ctx.attachShader(programObject, vertexShaderObject);
this.ctx.attachShader(programObject, fragmentShaderObject);
this.ctx.linkProgram(programObject);
if (!this.ctx.getProgramParameter(programObject, this.ctx.LINK_STATUS)) {
throw ("Error linking shaders:" + this.ctx.getProgramInfoLog(programObject));
}
return programObject;
};
在此特定调用中,该函数使用point.vert和basic.frag。
point.vert
attribute vec3 aVertexPosition;
attribute vec4 aVertexColor;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform float uPointSize;
//for undetermined point attenuation feature
// uniform vec3 uAttenuation;
uniform vec3 uBias;
uniform vec3 uScale;
uniform int uCEMode;
varying vec4 vColor;
void main(void) {
if(uCEMode == 1) {
//use bias and scale unifroms for min max color enhancement
vColor = (aVertexColor - vec4(uBias, 0.0)) * vec4(uScale, 1.0);
}
else {
vColor = aVertexColor;
}
vec4 ecPos4 = uModelViewMatrix * vec4(aVertexPosition, 1.0);
//make points larger as they get further away from the viewer
//helps to make the cloud look less sparse when far enough to only see
//the first level or two of the octree
gl_PointSize = length(ecPos4) / uPointSize * 3.0;
//for undetermined point attenuation feature
// float attn = uAttenuation[0] + (uAttenuation[1] * dist) + (uAttenuation[2] * dist * dist);
// gl_PointSize = (attn > 0.0 && attn < uPointSize) ? uPointSize * sqrt(1.0/attn) : uPointSize;
gl_Position = uProjectionMatrix * ecPos4;
}
basic.frag
varying highp vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}
我可以在声明vColor之间看到的唯一区别是highp说明符。如果我从basic.frag中删除它,它会指出“Uncaught ERROR:0:1:'':没有为(float)指定精度”。如果我在point.vert中的声明中添加highp,则没有任何变化。我假设那个特定的说明符很好。以下是Chrome中js控制台的错误消息:
Uncaught Error linking shaders:Varyings with the same name but different type, or statically used varyings in fragment shader are not declared in vertex shader: vColor
答案 0 :(得分:0)
将其添加到片段着色器的顶部:
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
然后从basic.frag中删除“highp”。
那可能会这样做,但我同意你没有给我们足够的肯定。
- 键