Best way to generate Normals?

Started by
3 comments, last by NotTaxes 21 years, 5 months ago
I am currently able to generate vertex normals using the triangle normal calculation. The problem with this is that it''s giving me FLAT shading on my terrain because the entire triangle is shaded with all the vertices having the same normal. I''ve been playing around with the algorythm to try and use points outside of the vertex''s triangle to generate different normals for each vertex and achieve a SMOOTH shading. What I''ve got looks much better, but it''s still not perfect - I''m taking the average of two inclines from a quad around the vertex. Is there a faster and cheaper way to get the right normals?
'Doing the impossible is kind of fun' - Walt Disney
Advertisement
Usual way to generate vertex normals is to average the normals of all triangles using a point.

   2-------5   /\  C  / \  /  \   /   \ / A  \ /  D  \1------3-------6 \ B  /  \  /   \/   4 



[assuming the ASCII art came out] Consider the above "mesh". It has 4 triangles, A,B,C and D and 6 vertices (1-6).

Vertex 1 is shared by polygons A and B so its vertex normal is simply the average of the FACE normals of both A and B. Doing the same for the other vertices:

v[1].n = (A.n + B.n) / 2
v[2].n = (A.n + C.n) / 2
v[3].n = (A.n + B.n + C.n + D.n / 4
v[4].n = B.n / 1
v[5].n = (C.n + D.n) /2
v[6].n = D.n / 1

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

OK, that''s similar to how I''m handling it, but I''m using fewer points. Thanks simon.
'Doing the impossible is kind of fun' - Walt Disney
I''m new at this, so i was wondering about something i read in "Beginning Direcr3D Game Programming" bye W. F. Engel. And on pg 29 when he introduces normals he has a tip that says:

"Direct3D applications do not need to specify face normals; the system calculates them automatically when they are needed".

Now, like i said, being new at this, i thought that sounded like an incredible feature. Then i noticed he specifies them in his own code later. So i was wondering what the deal is with how to do normals the "right" way.

--Ninj4D4n
it does compute FACE normals, not vertex normals. drawing in the D3DSHADE_FLAT mode does this. You need to compute the normals in the D3DSHADE_GOURAUD mode, which will give you the smooth look. if you need to have a smooth model with some sharp/flat parts, then you need to have duplicate the verts at the transition, so they can have different normals. The SDK explains it better then me, but maybe you understand what i''m talking about, paste this into the index help..."Face and Vertex Normal Vectors"

This topic is closed to new replies.

Advertisement