Jump to content
  • Advertisement
Sign in to follow this  
Pero83

D3DXmesh, index buffer, vertex normals question

This topic is 2616 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 guys. I have been recently learning DX9 (c++, visual studio 2010).

Now, i managed to make a simple cube, using index and vertex buffers; having 24 vertecies, 24uvs and 24 vertex normals. Then i used index buffer to create faces so to speak, using these vertecies.

now, since i had equal amount of Vertices, normals and uv's, and since all were inside one vertex array element (struct), all was clear.




But, now i'm looking into meshes, and when i look OBJ file format, it cube has List of 8 vertecies (V), 14 uvs (VT), 24 vertex normals (VN), and 6 faces, each having 4 indices/uvs/normals.




So, this is where i'm getting confused. So i have 8 vertecies, yet 24 normals. As i learned so far, when i use vertex buffer in D3DXmesh, i will still need to put both vertex position AND vertex nomals (and uvs) in the same vertex array element. (struct). Is this true? If so, this is where i get confused. If i have 8 vertices, and 24 vertex normals, and i can't have 1 vertex pos, 1 vertex normal per each vertex element array.

The only solution to this as i see, is to duplicate vertecies, so that i end up with 24 vertices, and then each element can have 1 vertex pos and one vertex normal.




But somehow, that kinda seems to counterproductive to what index are used for.

So, before i start writing my own obj importer to d3dxmesh, i would like to be sure about this, so any comment is wellcomed.




Also, since this is mostly for learing, i want to make obj importer on my own, no third party tools or so.

Also, i will be looking into example that sdk provides, but it looks quite complex and is gonna take some time to get through it.




Anyhow, tnx!










Share this post


Link to post
Share on other sites
Advertisement

Hey guys. I have been recently learning DX9 (c++, visual studio 2010).

Now, i managed to make a simple cube, using index and vertex buffers; having 24 vertecies, 24uvs and 24 vertex normals. Then i used index buffer to create faces so to speak, using these vertecies.

now, since i had equal amount of Vertices, normals and uv's, and since all were inside one vertex array element (struct), all was clear.

But, now i'm looking into meshes, and when i look OBJ file format, it cube has List of 8 vertecies (V), 14 uvs (VT), 24 vertex normals (VN), and 6 faces, each having 4 indices/uvs/normals.

So, this is where i'm getting confused. So i have 8 vertecies, yet 24 normals. As i learned so far, when i use vertex buffer in D3DXmesh, i will still need to put both vertex position AND vertex nomals (and uvs) in the same vertex array element. (struct). Is this true? If so, this is where i get confused. If i have 8 vertices, and 24 vertex normals, and i can't have 1 vertex pos, 1 vertex normal per each vertex element array.

The only solution to this as i see, is to duplicate vertecies, so that i end up with 24 vertices, and then each element can have 1 vertex pos and one vertex normal.

But somehow, that kinda seems to counterproductive to what index are used for.

So, before i start writing my own obj importer to d3dxmesh, i would like to be sure about this, so any comment is wellcomed.

Also, since this is mostly for learing, i want to make obj importer on my own, no third party tools or so.

Also, i will be looking into example that sdk provides, but it looks quite complex and is gonna take some time to get through it.

Anyhow, tnx!


The OBJ format tries to eliminate duplicated data from your vertices so that the resulting file size is smaller, it does this by storing each individual triangle as a face. A face then consists of 3 indices into the position array, normal array and texture coordinate array. Two adjacent faces can now share the vertex positional data and even UV and normal data if they are the same.

A GPU however likes to receive interleaved data, so you will have to copy the data over when it is duplicated.

Share this post


Link to post
Share on other sites
Ah, so in other words, if i have cube with 24 normals, i need to have 24 vertices (x,y,z position values) aswell?




But that kinda sounds very unoptimized. Is there no way to optimize, similar to how OBJ does, so that gpu doesn't have duplicated vertecies and therefor reduce vertex number a lot?

Share this post


Link to post
Share on other sites
It's unoptimized only in terms of storage, but optimized in terms of how the GPU likes to recieve data. Storage isn't everything, and it's frequently the case that you may need to take a memory hit in order to get good performance. This is OK - storage is cheap and plentiful whereas performance isn't.

Besides, no current 3D API supports data with each vertex attribute de-duplicated.

Share this post


Link to post
Share on other sites

It's unoptimized only in terms of storage, but optimized in terms of how the GPU likes to recieve data. Storage isn't everything, and it's frequently the case that you may need to take a memory hit in order to get good performance. This is OK - storage is cheap and plentiful whereas performance isn't.

Besides, no current 3D API supports data with each vertex attribute de-duplicated.



As mghain says storage is less expensive then performance, OBJ is from a time when Hard drive space was still expensive as well so they try to eliminate as much duplicate data as possible. Most games now-a-days however store their meshes in a fast to process data format, so that loading times are low.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!