Is it possible to index different vertex attributes with different index buffers?

Let's say I've got a vertex which is part of many triangles. I can just reference those with an index buffer. But is it possible to share it's position but have different texture coords for each triangle? e.g.

``````+--+--+
|\ |\ |
| \| \|
+--X--+
|\ |\ |
| \| \|
+--+--+
``````

The center vertex, X, is shared. If I want each square to have a different texture then I would need to store four distinct UV coordinates for the centre vertex. Is this only possible by creating it four times?

-

No, this is not possible.

A vertex is defined as a set of properties:

• 1 position
• 0 or more texture coordinates
• 0 or more normals

Unfortunately, you can only use 1 index per vertex. You cannot have an index for positions, an index for texture coordinates and an index for normals.

So if you want to share a vertex between two triangles, where the only difference is the texture coordinate, you will have to create two vertices: one for each triangle.

-
Where are the colors? Or bone weights? Or any of the other attributes that aren't texture coordinates or normals? And what about vertices that don't contain positions at all, that generate them in the vertex shader? See, a vertex is just a combination of attributes; exactly what they mean is up to you and your shader. – Nicol Bolas Jun 13 '12 at 14:57
"These are not the magical space savings you are looking for" (waves hand) – Patrick Hughes Jun 13 '12 at 15:24

No, it isn't. The GPU only supports the concept of a single index buffer being bound at a given time; graphics APIs expose this fact by only providing scalar methods for setting index buffers (that is, they only let you set one at a time).

In general this isn't a concern, although it seems wasteful at first glance. Most complex 3D models wouldn't be able to share a significant portion of their non-position vertex attributes anyhow -- things like cubes are a pathological case.

It also shows up when you're building grid planes for things like tiled backgrounds in 2D games, but in such games the footprint of your geometry overall is generally much smaller so the minor waste that occurs in the data duplication isn't usually worth noting. If it ever does become problematic there are higher-level approaches to reducing the geometry set that can be applied (such as rendering fewer tiles).

The architecture of GPUs has advanced to a point where theoretically this wouldn't be a terribly difficult feature to support in some new hardware, but the sheer lack of demand for it from any major players means the cost/benefit ratio isn't in anybody's favor.

-