Skip to main content
GameDev.net gamedev.net
🔒 Locked

Generating vertex normals...

Started by Zantac Oct 10, 2000 at 8:17 PM 3 replies 250+ views
Original Post
Zantac
Zantac
Hi everybody! I''ve got a little prob.. i need vertex normals for nice shading on my objects. I generate them by averaging the face-normals for every face that share a particular vertex. The problem is i use meshes with quite a high vertexcount (15000-20000) and it takes AGES and AGES to generate the vertexnormals (up to 10 seconds for a single mesh!!). Does anyone know a smart way of doing this, so i don''t have to use this brute-force method (comparing each vertex with every face)?? There must be a better way because when i load the file into 3DSMax it generates all the normals in less than a second. Thankful for your help, Simon
MK42
MK42
Sure, here''s a cool way:

For every triangle add the triangle normal to the vertex normal of each vertex in the triangle. For each vertex, keep track how many normals have been added (have a temporary array or something and increment that).

Then loop through all vertices and divide the vertex normal by the number of normals that contributed to it. This averages the normals of all triangles which share this vertex, which is what you want.

That should be the fastest way...

- MK42
WitchLord
WitchLord
Just a slight modification of MK42''s algorithm. You don''t need to the average of the normals because it wouldn''t give you unit length anyway so you might as well keep the total. If you absolutely need unit length of the normals then you must normalize them by dividing with the length of the normals.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Zantac
Zantac
Ok, thanks guys! Will try.

/Simon
MK42
MK42
Oops, you''re right

- MK42

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.