Jump to content
  • Advertisement
Sign in to follow this  

index buffers and normals

This topic is 4647 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

I have a problem with rendering complex shapes. I'm using directX to view models rather than as a programming API. The models I'm looking at can have thousands of vertices as they are used for accuracy not memory/speed requirments. I'm using index buffers to store the information about the model. when a vertice is shared I get the normals for every face that uses it, then average it. The problem is that when it comes to rendering the averaging of the normals causes some shading issues. i.e. Near complex geometry straight planes can appear to be shaded. Image In this picture the plane that has the hole in it is completely flat. However becuase of the average normal it looks like it has a dip in it. Ideally I would like to store all the normals and call them back when it comes time to render. e.g One normal for each face. But I don't have any idea on how to do this. My only thought so far is to not indexbuffer the model. But keep a seperate indexbuffer for the vertices, and an array for the normals. For each rendered frame I would apply the transformation matrix to a copy of the index buffer, then lock the model, copy all the vertices accross from the index buffer (thereby eliminating floating point drift and cutting down on processor time) then stick in the normals from the array, unlock the model and render. I'm not sure how efficient this would be though. Any help on where to look to solve this problem would be much appreciated. cheers DRB2k2

Share this post

Link to post
Share on other sites

It's probably this problem : Imagine a cube. With only triangles. Now, take one corner. You have 3 sides connected. 2 cases arise : for one side, you have 2 coplanar triangles connected to the vertex, or you have only 1 tri. So, if for 1 corner you happen to have 2 tris for 1 side, and only 1 tri for the 2 other sides, your normal will "lean toward" the first side (you have 2 tris, so 2 normals for that side)

I don't know if I was quite clear in my example ^^''

But anyway, if you want to properly compute the normals, you have to take into account more than only the tris connected to a vertex. One solution is (as far as I remember) : for vertex, consider all the tris connected to it. For each tri, compute the normal AND the angle formed by the 2 segments connected to this vertex. When you compute the sum of all the normals, use this angle to weigh the normals.

Back to the cube example : in the case of 2 tris for one side, both tris will form a 45° angle. In the case of 1 tri for one side, the angle is 90°
So, you have :

normal0, 45°
normal1, 45°
normal2, 90°
normal3, 90°

with normal0 == normal1. And when you will compute the vertex normal, the result will give something like :

normal0 / 2 + normal1 / 2 + normal2 + normal3 == normal0 + normal2 + normal3

As you see, you now have a good result since both coplanar triangles have the same normal, but only half the angle of the other tris.


I wish I could explain myself in a clearer way in english T_T
I hope you understood what I tried to explain ^^''

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!