0
\$\begingroup\$

I am writing an MD5 3D model loader to display animated models. The vertices and texcoords load in correctly, but the lighting is supposed to be smooth. I calculate per-vertex normals by looping through all triangles, finding the triangle normal, and then adding that to each of the triangle's vertices' normal (follow?). Then, I normalize all the normals. This should work, but md5 declares each vertex with a texcoord, meaning that if I have a single vertex that has different texcoords for each of the faces it's attached to, it declares multiple vertices at the same position. Each of these will end up with its own normal, resulting in flat shading. Should I somehow merge duplicate vertices, or export the model differently, or do something fancy that I haven't thought of?

Thanks!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If you want smooth normals everywhere you will need to deduplicate vertices for normal calculation purposes. So instead of "for each vertex, for each index, if index value == this vertex, add normal" you'll need to use "for each vertex, for each index, if vertices[index value].pos == this vertex.pos, add normal".

\$\endgroup\$
1
  • \$\begingroup\$ Thanks. I was using a tutorial from off this website, but it just has the simple loop that I described. I didn't exactly want to use this method, but it works, and not much else is going to, so thanks a bunch! \$\endgroup\$ Dec 1, 2014 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .