Hi!
I made a 3d model and I load it into OpenGL ES, but the illumination is wrong! I look at the example simplelightin particular the duck model: the number of the normals is the same of the vertices; I try a to make a lot of simple model but the number of the of normals is never equal to the vertices number. Hoe Can I have a correct illumination of my model?
Thanks!
OpenGL ES (and standard OpenGL API, when used with vertex arrays) takes the per-vertex data from the vertex arrays. Whenever Nth vertex coordinate is fetched from corresponding vertex array, color/normal/texture coordinate is fetched also from Nth position in the corresponding array.
If your model does not have normals for each vertex, you will have to replicate normals so that every vertex coordinate has also some meaningful normal behind the normal array at the same index. Some options:
- duplicate normals (some normals may not be valid depending on how you do it)
- generate normals by yourself from the triangle data in the application (normal for vertex N in typical application is the average of the normals of triangles that share vertex N)
- generate normals in similar way in some external tool
- find an exporter that is able to generate the right normals (for each vertex)
In my opinion, the best solution is to not store the normals and just generate them during the initialization phase (smaller model file). In typical application (not requiring hand-tuned normals for some lighting tricks), averaged normals of connected triangles is enough.
Thank you very much for your answer!
In my case, I've created a cube in milkshape3d and exported it in a .h file. In this file I have 20 vertices, 12 faces and 6 normal: