UVs + index/vertex buffers.

Goragoth

Regular
While writing my exporter for Maya I came across a little problem that I hadn't considered before: UV coordinates are not necessarily unique for each vertex in a mesh. In general most vertices will have the same UV coordinates for all triangles connected to them but at texture seams this will not be true.

One (not very good) solution would be to just abandon indices and write out each triangle as three vertices but this would have a significant impact on performance and size.

The only good solution I can come up with to only duplicate vertices along texture seams. Is this the right way to handle this problem? It would make things more complicated for my exporter but its the only way I can see that would make sense.
 
Goragoth said:
The only good solution I can come up with to only duplicate vertices along texture seams. Is this the right way to handle this problem?
That approach would make the most sense.

Actually, it's been so long since I looked at the details of the API, but does D3D still have the texture "wrap" mapping mode? That would reduce the number of vertices for you. It was always a pain to support in HW so it may have been killed off.
 
Simon F said:
Actually, it's been so long since I looked at the details of the API, but does D3D still have the texture "wrap" mapping mode?
Yes I believe it does, I was just reading about it before but thanks for pointing that out as it would indeed reduce the number of vertices needed although I'm not sure how easy it would be to figure out when it could be used. Right now I'm not even sure how to figure which vertices are along seams and which aren't, this is a complication I frankly hadn't thought about at all until I started to get the UV data from Maya and realized that there were more UVs than vertices :oops:
 
You just need to add the addional vert.

Stop thinking of a vert as a position in 3 space, it's a descriptor in N space where N is the width of the vector including Position Normal any number ofd UV's and any number of Colors (depending on what your supporting). If any of those are unique then the vertex is unique.

We used to have a lot of problems with artists tweaking UV coordinates on a tri by tri basis, and creating 2 or 3x the number of original verts, the only real solution is to explain why it's a bad idea to the artist but this practice seems to be a much less prevalent technique with higher polygon models.

IME excpt on very low polygon count models it doesn't at hugly to the vertex count.
 
Code:
typedef enum vertexAttribute_e { kPosition, kNormal, kTexCoord0, kTexCoord1, kColor };

template < unsigned int N >
class tuple {
private:
	int values[N];
public:

	tuple() {
		for( unsigned int i = 0; i < N; ++i ) {
			values[i] = 0;
		}
	}

	int & operator []( const unsigned int idx ) {
		// csz perform error checking here
		return values[idx];
	}
	int operator []( const unsigned int idx ) const {
		// csz perform error checking here
		return values[idx];
	}
	bool operator<( const tuple &other ) const {
		for( unsigned int i = 0; i < N-1; ++i ) {
			if( this->values[i] != other.values[i] ) {
				return this->values[i] < other.values[i];
			}
		}
		return( this->values[N-1] < other.values[N-1] );
	}
};



std::map< int, MVector > subMeshVertices;
std::map< int, MVector > subMeshNormals;
std::map< int, MVector > subMeshTexCoords[ 2 ];
std::map< int, MColor  > subMeshColors;
		
		
// maps the unique vertex attribute index to an unused slot
std::map< vaTuple, int > uviMap;
std::map< MFloatVector, int, lt_compressed_normal > compressedNormalMap;

Here's a simple example from my Maya exporter
 
After thinking about the problem for a while the simplest solution seems to be just to add all the vertices (i.e. 3 per triangle) and when adding just check against those vertices already present if a match is found don't add but return an index instead.

ERP said:
Stop thinking of a vert as a position in 3 space, it's a descriptor in N space where N is the width of the vector including Position Normal any number ofd UV's and any number of Colors (depending on what your supporting). If any of those are unique then the vertex is unique.
I know what you are saying and I guess its not that much of a problem its just the way I see it this means that the hardware has to TnL additional vertices that differ only in their UV coordinates which seems like such a waste. If UVs could instead be kept seperate from the vertices themselves and somehow be referenced by the hardware by face/vertex combination you could save some transforms. I guess that's not possible so additional vertices it is ;)
 
Actually some hardware (outside the PC space) has seperate indices for Positions, Normals and Texture coords. But even then they don't cache the result seperately, so it doesn't save any calculations.
 
Back
Top