Sign in to follow this  
enigmatix

Texturing Indexed Primitives

Recommended Posts

enigmatix    144
I've been thinking about it for a while now and I was wondering what the best is to go about texturing an object with a single image if its using an index buffer. Since one triangle will probably use a texture coordinate that forces another triangle to use it as well, how can you perform texture atlasing? I know you can separate each triangle to have independent vertecies, but it just seems so wasteful if you can do indexing. I also thought about using a flexible vertex format that can store many texture coordinates, but then you still have the issue of not knowing how many triangles use a single point. Is there a more logical way of doing it? Because right now, I'm thinking of making all the triangles not use indexing...

Share this post


Link to post
Share on other sites
sirob    1181
Quote:
Original post by enigmatix
I've been thinking about it for a while now and I was wondering what the best is to go about texturing an object with a single image if its using an index buffer. Since one triangle will probably use a texture coordinate that forces another triangle to use it as well, how can you perform texture atlasing? I know you can separate each triangle to have independent vertecies, but it just seems so wasteful if you can do indexing. Is there a more logical way of doing it? Because right now, I'm thinking of making all the triangles not use indexing...


First off, it isn't that wasteful. The hardware is designed to transform a large number of vertices. While doing a few more would take it longer, it isn't that much longer.

Don't get me wrong, you'd still want to minimize this as far as possible, but going to extents of packing multiple texcoords in a vertex and "picking" the right one, forget about it, it wouldn't be worth it even if it were possible.

You can use several techniques to make sure you produce as little duplicates as possible, but those techniques usually apply to how a model is actually textured by an artist, and, in most cases, cannot be "redone" after a model is textured.

If you're into how models are textured, or you're doing some form of procedural texturing, this might somehow be relevent, but if you're just loading a model from a file, there's simply nothing you can do about. Make your VertexShader as streamlined as possible, so that when you are forced to transform the same vertex twice, you do as little extra work as possible.

If you're looking at procedural texturing, there's a D3DX Atlasing API, and I also recall an NV Atlasing API, so you might want to look at those.

Lastly, a small note. The fact you have a single vertex in the vertex buffer, and it is used twice by the index buffer doesn't necessarily mean it is only transformed once. The GPU has a cache of recently transformed vertices. If a vertex was used too long ago to have remained in the cache, it will be processed again from scratch. This means that if you don't get cache hits on vertices, having two different vertices or one vertex that gets used twice only affects your memory use by the vertex buffer.

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this