Reputation: 50
I'm trying to read vertex and face info from a file and calculate the vertex normals. I've read lots of other answers but I'm still not sure I understand. The consensus is that the vertex normals should be the average of the surrounding face normals, which makes sense at first glance. For a cube the normals should all be at 45 degrees. Is that right? Because the calculations only come out like this if the triangles are arranged in such a way that each vertex shares either 3 or 6 'faces.'
Question:
If a cube has a vertex with, say, 4 triangles, should I weight them somehow so that the normals do come out at 45 degrees. Or should I sum the face normals? Does OpenGL expect the vertex normal to slope more towards the face with 2 triangles? Also, should I normalise the face normals before summing?
Upvotes: 0
Views: 1037
Reputation: 1
cube can't have vertex with 4 triangles.trade this stuff to 3d modellin soft like art of illusion,export model as .obj
with 'write surf normals' and write obj loader(one page of C code,link posted already) .
normals in a triangle that you'll see there are not the same.And after it arrives to a shader it's interpolated there between all 3 verts so there are one normal per fragment(smth close to pixel) finally.
Upvotes: 0
Reputation: 7198
Modern OpenGL (version >= 3) knows nothing about normals. It's you who use them in a shader to do things like shading. The concept is handling normal direction and light direction.
If your triangle is flat, it only needs exactly one normal, the same for every point inside the triangle. If you want some "curve" effect, you can set different normals at each vertex and see the resulting effect when the normal at each point is interpolated among the normals at vertices.
If your model is smooth, no visible edges between two triangles, then the normals for two side-by-side triangles can be considered the same normal.
If your shader reads normals the same way it reads vertices, then you have to provide for every triangle three normals. If they are the same normal, you have a flat triangle, otherwise you get the other effect.
If your model is smooth, then the normal for a vertex should be the same as for neighbour points. That means that you compute a weighted normal from normals in near points/triangles. A cube is not smooth, so the normal for each face is independant of neighbour triangles.
Upvotes: 1