# Index Buffer & normals

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

## Recommended Posts

Hey guys,

I am trying to optimize my code a bit with vertex buffer and index buffer.

What do you do when you have a shared vertex but it is suppose to have different normals?

This is rendered without index buffer.
But to clarify my problem... the north vertex and the vertex at the cube edges shares the same vertex, but they have different normals.

How can I achieve this when using vertex buffer and index buffer... because the vertex buffer can't have duplicate vertices.

Thanks guys

##### Share on other sites
Quote:
 Original post by tenpoundbearbecause the vertex buffer can't have duplicate vertices.

Why not? That's usually how this problem is handled.

##### Share on other sites
Unless things have changed radically in DX 10/11, you can only have one index buffer active at any given time, and all vertex buffer streams must be indexed using that buffer.

This means that (e.g.) if you have multiple vertices that share a position but have different normals, you'll just need to create multiple copies of the vertex (one for each unique normal).

##### Share on other sites
Quote:
Original post by MJP
Quote:
 Original post by tenpoundbearbecause the vertex buffer can't have duplicate vertices.

Why not? That's usually how this problem is handled.

Hmmm... from the texts I've read and tutorials I looked at on the net, its says you don't.

I guess the commonly used example is the cube...

3 * 2 * 6 = 36 vertices (3 vertex/per triangle, 2 triangle/per face, 6 faces)

The purpose of VB & IB is so that the duplicate vertices are removed, hence only 8 vertex needed for VB. And using IB, all the faces can be indexed just from the 8 vertex alone. Faster, more efficient rendering.

This is how I understand it anyways... let me know if I am wrong.

##### Share on other sites
Quote:
 Original post by jykThis means that (e.g.) if you have multiple vertices that share a position but have different normals, you'll just need to create multiple copies of the vertex (one for each unique normal).

Hmmm... this sounds more trouble then it is worth.

Using my image in the OP as example, the top 4 faces will have shared vertices... hence you are suggesting I create another 4 vertex buffer to accommodate the normals?

Sorry I don't exactly know what you mean :)

##### Share on other sites
Quote:
 Original post by tenpoundbearUsing my image in the OP as example, the top 4 faces will have shared vertices... hence you are suggesting I create another 4 vertex buffer to accommodate the normals?
(Assuming you mean "create another 4 vertices"), yes. A vertex is not a position, a vertex is a position, normal, texture coordinate, diffuse colour and anything else you need to describe one vertex.
If you have two positions that are the same but with two different normals, then they are two discreet vertices.

Likewise if you have two vertices, one with a position (0, 0, 0) and with a colour of RGB(1, 0, 0) and one with a position of (123, 456, 678) and a colour of RGB(1, 0, 0) they're discreet vertices, even though they share one component.

Modelling packages generally define a vertex as a position with no other attributes, that is not the case in DirectX or OpenGL.

##### Share on other sites
I see.. I understand now :)

I just assume.. if same position then same vertex. But as you pointed out, there are other properties too that determine this.

Thanks :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634084
• Total Posts
3015403
×