Jump to content
  • Advertisement
Sign in to follow this  
NathanRidley

Texture coordinates and shared vertices

This topic is 1440 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'm learning how to texture a model at the moment and there is something I'm unsure of. The tutorials I've read all seem to apply the texture coordinate per-vertex, which works fine if you're, say, mapping a texture onto terrain, but what about the case of a cube, where each vertex is shared by faces that are orthoganl to each other? The vertex would need a different texture coordinate depending on the face being textured. But DrawIndexed simply takes a buffer of values specifying the indices of the vertices that make up a face- there doesn't seem to be any way to specify any metadata relating to the face itself. When two different faces need to be textured differently, do they simply need their own unique copies of a vertex in order to achieve this, even though some of the vertices will be duplicated just for the sake of having different texture coordinates?

Share this post


Link to post
Share on other sites
Advertisement

When two different faces need to be textured differently, do they simply need their own unique copies of a vertex in order to achieve this, even though some of the vertices will be duplicated just for the sake of having different texture coordinates?

Not always, but often, yes.

You can sometimes unwrap the faces in a way that they unfold onto a 2d texture, and the shared coordinates are correct, but this doesn't always work (depending on what you need).

See attached file: Something like that will give you a cube texture (not great) with only one triplicated vertex. You can also just do one duplicated by bringing two of those corners together (in exchange for more distortion).

You could also do something tricky, like use multi-texturing and blend the texture according to the normals, like triplanar texturing, or just use standard triplanar texturing if it doesn't matter how the texture is applied. However, that will also give you pretty nasty results if you're using the vertex based interpolation for your normals (and grabbing normals from shared vertices).
If you want it pretty, you'd have to calculate your normals on the fly based on the depth buffer or something.

Share this post


Link to post
Share on other sites

Thanks, that clears things up for me. I'm not too worried about doing anything tricky right now, mainly for now I just want to make sure I have a handle on the "normal" ways that these kinds of things are done. p.s. you forgot the attachment you mentioned.

Share this post


Link to post
Share on other sites


The vertex would need a different texture coordinate depending on the face being textured.

no, it is not a matter of texture coords. In fact, all sides which shares a vertex can share its texture coord too.

 

The real matter is, that when rendering a vertex, it needs to be complete, that is, all data associated with a vertex must be present as unique data block. This is often the position, texture coord, normal, vertex color etc. If many surfaces shares a vertex, you need to divide them up into unique vertices when rendering.

 

Eg  you have a flat shaded shaded, textured cube, then each vertex might share the position, uv and vertex color of three neighbor surfaces, but often the normal needs to be different. In this case you have 24 unique vertices for the 6 surfaces of it. If they would although share the normal and the uv (eg all have the uv of 0,0), then you would only need 8 unique vertices.

Share this post


Link to post
Share on other sites

p.s. you forgot the attachment you mentioned.


It's on there for me. It messed up uploading the first time, you may have seen the post in the minute between posting and my second attempt (which seemed to work).

Is this working?

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!