问题
I wanted to play with THREE lod system, and I applied normal mapped material on my meshes but it failed with GL errors :
WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2
Anyone can reproduce it quite easly I think, just edit the webgl_lod example, and instead of applying a MeshLambertMaterial use the normalmap ShaderMaterial provided in the misc_control_fly example.
Am I missing something, isn't the normalmap shader supposed to work with LOD meshes ?
edit: here is links to see the problem.
original example webgl_lod that is working : http://typedef.byethost8.com/examples/webgl_lod.html
with normalmap shader from shaderLib instead of original meshLambertMateriel of web_lod example : http://typedef.byethost8.com/examples/failing_webgl_lod.html
回答1:
You have to generate the tangents for your geometries. Add:
geometry[ 0 ][ 0 ].computeTangents();
geometry[ 1 ][ 0 ].computeTangents();
This will get rid of the error:
WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2
Also, I had to use sheres instead of planes to see something displayed => maybe texture coordinates are not generated for planes ? Or the normalmap material does not work with planes ?
来源:https://stackoverflow.com/questions/15717468/three-lod-and-normalmap-shader-fail