Thursday, April 8, 2010

Optimum Lightmap Sizing

In other news I've been working on tuning the lightmap size for DirectQ. This wasn't a problem in GLQuake as it could mostly target single-texture cards and didn't support huge maps. Older, more innocent times.

It's a very fine balancing act, as the objective of a multitextured/texturechained renderer is to try and ensure that as many surfaces which share the same texture as possible also share the same lightmap. Otherwise the overhead of texture changes (potentially as many as one change per surface) means that a single-textured renderer may well be faster.

You've also got to balance performance in ID1 maps with performance in huge maps. I've found that using tall-but-narrow lightmaps gives good results but the question is how tall and how narrow?

It's further complicated by the fact that there seem to be a number of sweet spots where things appear to balance out well, so you've got a lot of testing to do. Also, there will almost always be aberrant cases where you're basically fighting the map design and eventually just have to accept what you've got as the best you can do for now.

Previous versions of DirectQ (in the 1.8.x series) used a 32 texel wide lightmap and set the height at the max texture height supported by the card. This worked well but had the disadvantage that if even one surface overflowed into a new lightmap you wasted a whole heap of texture memory. It also seemed slightly prone to texture trashing on Debug builds running in the debugger under WDDM drivers (but so is everything; just that it was especially bad).

For 1.8.3 I've discovered that 64x512 lightmaps also represent another of those sweet spots. There's a saving on texture memory on the overflow case, the lightmaps seem to bind to a TMU faster, and you can still pack a good many surfaces sharing the same texture into a single lightmap. Overall performance is up quite a bit in both ID1 maps and huge maps, but it's still possible to construct a scene that's designed to make it suffer (that will always be the case).

No doubt there are other lightmap sizes which offer other tradeoffs and balances, and no doubt at some point in the future I'll come back to those and work some on them, but for now what I've got is a good enough improvement.

0 comments: