THREE.lod and normalmap shader fail

南楼画角 提交于 2019-12-12 04:49:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!