The mis-adventures of a new Game Developer.
Daily 09/22/03 Supplement
Published on September 22, 2003 By Mudflap In Software Development

This weekend, just days before the demo, we came across a major problem...Texture thrashing!!!

Texture thrashing was our single largest contributor to a recent framerate drop. We added 50% more textures on Friday and this pushed our 64 meg video cards over the edge. Instead of the clean 60+ frames, my laptop went down to 1~2 frames. Ouch.

After much discovery I found out that our textures are just way to big. They were cool to play with. Unfortunately, as the number rose our framerate dropped. Our biggest offender was the colony ship texture coming in at a whopping 2048x2048. In reality, our colony ship in full screen didn't take up more than 500 pixels on the screen. A gross waste.

What we want to strive for to get clean artwork is a 1:1 pixel to texel mapping. What does this mean? It means that if your texels are less than one pixel in size, you're not getting full texture fidelity. Not a big deal, but it can look as bad as some bad texture stretching. Especially if your texture has a lot of detail like ours. So you want to scale your texture so that it roughly matches at full zoom. Also, if we can get away with a lot less detail in the texture, we can shrink it again.

Looking at games like Homeworld2, you can tell that they do a lot of custom texture management. It's really evident if you set it up so that you get a really low framerate. If you zoom in on a ship real fast, you'll see the texture mip levels recalculate on the fly. It's pretty cool.

Here's some texture math for our artists so that they have an idea of what we're against.

Disclaimer: This is a pseudo artist's rendering of the problem. It's meant for artist eyes. If you're a programmer, you know that it's different then this

Here's an example of bad texture usage. This is where thrashing happens. Notice that not all the textures don't fit into memory at one time. The time to swap out a texture becomes significant. Also notice that the textures aren't scaled to the size or importance of an object. For instance, the phasor blast isn't more than 20 or 30 pixels on the screen. There's no reason it should be close to the size of a star texture that can take up the entire screen.

Here's an example of good texture usage. Notice that all the textures are fit into memory and their sizes are roughly equivalent to their importance and size on the screen.

This image gives you perspective on texture sizes. In on 2048x2048 texture, you can fit:

  • 4 - 1024x1024 textures

  • 16 - 512x512 textures

  • 64 - 256x256 textures

  • 256 - 128x128 textures

  • 1024 - 64x64 textures

So, the bottom line. Watch your textures closely. Don't make them larger than they have to be. They'll eat your framerate alive!!!


Comments
on Sep 23, 2003
Yup sounds like that crazy AlexG is up to his no good tricks again:p Chances are he's working big and passed off a larger texture map than he meant to. Assuming the map is well laid out a 256*256 skin would be more than enough for the size of the colony ship and you would be able to get far tighter detail than anything out there right now with a 512*512. Just a thought;)

BTW, I'm enjoying keeping up to date with what you guys are up to here...very cool stuff
on Sep 23, 2003
Hey Paul! Glad to see you're still in the loop! Joe here Is our resident 3D guru and it kicking butt at organizing things over here (some of the guidelines and learning procedures he's teaching would make you proud).

Anyways, my 2 cents about the whole thing is that, come time for creating textures for alien ships, we organize them in a way where all the colors can be applied on the fly (like we did with political machine). There had been discussions of making seperate textures for each of the different races.

Assuming 12 different races, with 25 different ship-bodies apeice (plus a specular map per ship), that comes to 325 256x256 textures for ships alone, with 25 more textures for each additional race.

If we had went the "layered texture" route, each ship would have:
- a base texture (hull, panneling, ect)
- a details texture (windows and weaponry)
- an alpha texture used for displaying the main race color (warp engines and paint job)
- and a specular map
The base texture and alpha textures could be tinted accordingly, with the details staying a set color. This would limit the about of difference between race's ships, but could drastically cut the necessary number of texture maps needed. With 4 textures per ship, and 25 ships in the game, only 100 256x256 textures would be needed (with additional aliens requiring no new textures).
In fact, using this meathod you could probably bump up the "base" and "details" textures to 512x512 images, giving crisper ships up close and still only using the equivilant of 250 256x256 texture maps.

Anyways, thats my attempt at looking smart Hopefully I added something to the conversation.

ScottT OUT!

on Sep 24, 2003
Sounds about right... I like the idea of having the weapons on a seperate texture sheet so that they can be changed up easily and shared between ships. I'm curious how much the specular map will add to the ships(i.e. if it wouldn't make more sense to bake the specular highlites into the diffuse map?) Especially since we're generally seeing the ships from a 3/4 view. Has there been any though to using a bump channel? I wonder if it would be possible to get a bump and specular map on one sheet? Or if that'd be even worth it at such a small size?...just thinking out loud.
on Sep 24, 2003
There's been some talk of baking the specular map directly on the diffuse, or just using a separate specular map. That'll take some load off the GPU. I think that if we're going to use a specular map anyways, we should just bake it into the diffuse. It's one texture that way. Using a specular map also means that the specular highlights won't change so we may as well put them into the diffuse.