Jump to content

Compressed Vertex Arrays


Josh

1,861 views

 Share

My work with the MD3 format and its funny short vertex positions made me think about vertex array sizes. (Interestingly, the Quake 2 MD2 format uses a single char for vertex positions!)

Smaller vertex formats run faster, so it made sense to look into this. Here was our vertex format before, weighing in at 72 bytes:

struct Vertex
{
	Vec3 position;
	float displacement;
	Vec3 normal;
	Vec2 texcoords[2];
	Vec4 tangent;
	unsigned char color[4];
	unsigned char boneweights[4];
	unsigned char boneindices[4];
}

According to the OpenGL wiki, it is okay to replace the normals with a signed char. And if this works for normals, it will also work for tangents, since they are just another vector.

I also implemented half floats for the texture coordinates.

Here is the vertex structure now at a mere 40 bytes, about half the size:

struct Vertex
{
	Vec3 position;
	signed char normal[3];
	signed char displacement;
	unsigned short texcoords[4];
	signed char tangent[4];
	unsigned char color[4];
	unsigned char boneweights[4];
	unsigned char boneindices[4];
}

Everything works with no visible loss of quality. Half-floats for the position would reduce the size by an additional 6 bytes, but would likely incur two bytes of padding since it would no longer by aligned to four bytes, like most GPUs prefer. So it would really only save four bytes, which is not worth it for half the precision.

Another interesting thing I might work into the GMF format is Draco mesh compression by Google. This is only for shrinking file sizes, and does not lead to any increased performance. The bulk of your game data is going to be in texture files, so this isn't too important but might be a nice extra.

  • Like 2
 Share

2 Comments


Recommended Comments

In fact, Leadwerks model files are usually measured in kilobytes rather than megabytes, so compressing those further would make very little difference in your game data size.

Link to comment

My best guess is this yielded a 7% performance boost, across the board. I'm not going to test in detail because it takes a lot of changes to modify the vertex format.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...