Jump to content
  • Advertisement


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


Vertex Buffer Headscratcher

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

Ok, this is a wierd problem so bear with me. Our engine supports meshes that can have multiple textures AND materials. Upon loading a mesh, our engine groups each face in the mesh by it''s material/texture forming what we call a mesh group. Now when it comes time to render a mesh, we transform it from local to world and then we do a for loop for each group in the mesh, set the current texture and material for the group and then render it using DrawIndexedPrimitive. Like this: (pseudo code...not an actual snippet) for (i=0; iNumGroups; i++) { SetCurrentTexture(Mesh->MeshGroup(i).Texture); SetCurrentMaterial(Mesh->MeshGroup(i).Material); DrawIndexedPrimitive(D3DFVF_VERTEX,Mesh..........) } Now, the problem with this is that DrawIndexedPrimitive retransformes from world->view space the entire mesh FOR EACH GROUP when really it should be transformed once. Logical soloution? Vertex buffers. BUT, now the problem lies with the fact that if we have 1 or more materials per mesh, we have to relight the mesh for each material. This poses a problem with vertex buffers because you transform them once and then render each group seperatly. As a side note, I thought that once the vertices were transformed and lit in the vertex buffer, the lighting information would be retained when rendering the different materials. IT seems that is not the case. Or is it and I am doing something wrong? ie. I transform and light a mesh that has 1 or more materials and no textures. The scene has 3 directional lights each pointing towards the mesh. The first material gets rendered but not the second or third. So....I''m stuck. Any suggestions from you guys would be very cool. Later ~----------------------------~ Fred Di Sano System Programmer Artech Studios Ottawa.CA ~----------------------------~

Share this post

Link to post
Share on other sites
After the vertices have been lit, the light information is stored in the diffuse and specular color attributes of the vertex. So a change of material after lighting won''t affect the outcome of the rendering.

My suggestion to you is to store the material properties in the vertices themselves. You can use the diffuse and specular color attributes for that end.

You just need to tell Direct3D where it can find the material properties and that is done with:


Of course you also need to change your vertex format to include the color attributes, but that shouldn''t be to much of a problem.

- WitchLord

Share this post

Link to post
Share on other sites
fdisano, I, too, am dividing my models into "groups" that share the same texture & material. It sounds like you are using one sorta "global" vertex list for all your mesh groups. Have you thought about giving each group its own vertex list? This would allow you to use DrawIndexedPrimitive (and hardware TnL).

This method results in a lot of duplicate vertices, along the edges of two groups. It turns out I actually need these duplicate vertices, though. Within a group, I smooth-shade all the faces, but, along the edges of two different textures/materials, I (logically) want to have "creases". These duplicate edge vertices need to have different normals in order to create the "crease".

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.

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!