0
votes

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?

2
For a cube, you wouldn't want any smoothed normals. You want hard edges.BDL
I'm reading from a file, cube's just a for example, how would OPENGL expect vertex normals?OffGridAndy
OpenGL does not define any restrictions on how normals have to look like. Actually, the term "normal" is not defined in any way in the current OpenGL 4.5 spec. You can basically calculate them depending on what fits best to your data/ what looks best.BDL
@BDL So, if I have a vertex with 3 surrounding polygon faces, each composed of 2 triangles... let's just say a cube corner. Will OpenGL do the same shading no matter how the triangles are arranged? Or, if 2 of the faces have 1 triangle touching the vertex and the third face is touched by 2, will this be drawn differently to the same shaped vertex (so to speak) but touched by 3 triangles (not 4)? I would of though the former to be the case but as many folk say to average the face normals perhaps the number of triangles does affect things.OffGridAndy
@immibis Yeah, thanks for your contribution and the wealth of information therein. No to mention your wit.OffGridAndy

2 Answers

1
votes

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.

0
votes

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.