#### Archived

This topic is now archived and is closed to further replies.

# Best way to generate Normals?

This topic is 5765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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

##### Share on other sites
OK, that''s similar to how I''m handling it, but I''m using fewer points. Thanks simon.

##### Share on other sites
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

##### Share on other sites
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"

1. 1
2. 2
JoeJ
20
3. 3
4. 4
5. 5
frob
12

• 10
• 13
• 21
• 13
• 20
• ### Forum Statistics

• Total Topics
632195
• Total Posts
3004702

×