Archived

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

jollyjeffers

averaging normals

Recommended Posts

hi, simple overview: I''m writing a terrain visualisation program in C++/D3D9. when i first implemented the engine, to keep things simple, when adding a triangle to the mesh I calculated the normal for each vertex to be that of the face normal. this worked great, but gives a rather flat appearance to the geometry (with lots of sharp edges to the lighting). I''ve now gotten around to implementing a smoothing-group method where I determine an individual vertex''s normal based on the orientation of the 6 triangles that share that vertex. heres'' my current ''algorithm'' 1. go through each of the 6 triangles 2. store the normal for each of the 6 triangles 3. add all of the normals together 4. normalise it is there anything wrong with this? The results on-screen is heavily dominated in the Y (up) direction, and as such the lighting doesn''t look right. are there any better/proper ways to sum up the averages of 6 triangles? cheers, Jack DirectX 4 VB: All you need for multimedia programming in Visual Basic Formula 1 Championship Manager, My Game Project.

Share this post


Link to post
Share on other sites
I treat my terrain as a function defined on a 2D domain. This function can be numerically differentiated to find partial derivatives, say dF/du and dF/dv. The cross product of these two is the surface normal. You never need to calculate face normals.

Share this post


Link to post
Share on other sites
hi,

unfortunately I dont think I can apply your idea of a "function on a 2D domain" as that would require some mathematical basis for the shape of the terrain (such as a bezier/cubic patch).

My terrain is read from a greyscale bitmap or a DEM file.

thanks for the suggestion though.

****

However, I've just been messing around, and pre-normalisation, if I divide the vectors Y by 6.0 (number of triangles) then it looks correct on screen.

have i just guessed the correct solution?

Jack

DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.

[edited by - jollyjeffers on March 15, 2003 9:24:14 PM]

Share this post


Link to post
Share on other sites
One question that pops to mind is why all the splits run the same direction. It seems with a relatively flat terrain that would tend to flatten it even more. Basically subtile curvitures are wiped out. You can make a terrain that is basically gullies running on the same diagonal. If you flip that then look at both they are going to look pretty substantially differantly. One is going to have relatively smooth sides to the gullies and the other fairly rough sides due to the splits running with the gully or against it. I have pretty limited knowledge so I might be off base, but food for thought.

Share this post


Link to post
Share on other sites