Jump to content
  • Advertisement

Archived

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

Etus

Calculating vertex normals for a terrain

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''ve been trying to calculate vertex-normals to a triangle-strip terrain. I''ve been trying to add this feature to GameTutorial''s terrain tutorial #2. Though, I didn''t manage to add this feature. I know how to calculate vertex normals for a model which uses regular triangles, but I have no idea how to do the same thing for triangle-strips. I''ve searched the net for a tutorial or a source code which does that, but found none. I''m using OpenGL to render, but I presume it doesn''t really matters in this case. Please, can you tell me what''s the algorithm to do it? Or, can you please link me to some tutorial/source code? Thanks, Yuval

Share this post


Link to post
Share on other sites
Advertisement
There are 2 solutions:
1) you calculate your normals before generating the triangle strips (if possible). You anyway will have to add them to the mesh (I guess).

2) when calculating from the strips, what exactly is your problem? You know what a strip is, so you know how to get the 3 vertices for your normal calculation. Go over your strip array, and get a vertex (starting with the third); the previous two vertices right before it are the other 2 edges of the triangle.

- thomas

Share this post


Link to post
Share on other sites
i''ve found that what works the best is to take each vertex and calculate the normal vector for each of the six triangles which contain it. average those normal vectors to get the normal that you will set when drawing the triangle strips. you end up with slight lighting inaccuracies on sharp peaks and valleys but if your terrain is largely rounded it looks good.

if you want better lighting, you should construct a lightmap for your terrain. that way you can construct the lightmap using a seperate normal for every single triangle on the mesh which will end up looking much better.

-me

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!