【发布时间】:2014-02-07 15:19:36
【问题描述】:
我正在尝试修复一些基于 THREE.js rev 49 和一些自定义着色器的代码中的一个预先存在的错误。
我完全是 WebGL 新手,所以我无法对其他答案做出太多正面或反面,因为他们似乎假设的知识比我所拥有的要多得多。我会非常感激任何关于寻找什么的提示! :) 代码的最终结果是绘制一个半透明的盒子线框,并用半透明的纹理绘制面部。
具体错误是:
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1
我将问题追溯到 THREE.WebGLRenderer.renderBuffer 中的特定 _gl.drawElements( _gl.TRIANGLES, geometryGroup.__webglFaceCount, _gl.UNSIGNED_SHORT, 0 );。
这是调用代码的sn-p:
scene.overrideMaterial = depthMaterial; // shaders below
var ctx = renderer.getContext(); // renderer is a THREE.WebGLRenderer
ctx.disable(ctx.BLEND);
// renderTarget is a THREE.WebGLRenderTarget, _camera, scene is obvious
renderer.render(scene, _camera, renderTarget, true); // error occurs here
以下是相关的着色器:
uniforms: {},
vertexShader: [
"varying vec3 vNormal;",
"void main() {",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalMatrix * normal;",
"gl_Position = projectionMatrix * mvPosition;",
"}"
].join("\n"),
fragmentShader: [
"vec4 pack_depth( const in highp float depth ) {",
"const highp vec4 bit_shift = vec4( 256.0, 256.0*256.0, 256.0*256.0*256.0, 256.0*256.0*256.0*256.0 );",
"vec4 res = depth * bit_shift;",
"res.x = min(res.x + 1.0, 255.0);",
"res = fract(floor(res) / 256.0);",
"return res;",
"}",
"void main() {",
"gl_FragData[0] = pack_depth( gl_FragCoord.z );",
"}"
].join("\n")
感谢您的帮助!
【问题讨论】: