Tuesday, December 29, 2009

Fun with Lightmaps

The "tall but narrow" lightmap approach worked perfectly. Lightmaps are now by default 32 texels wide (they can expand up to your max texture size if a surf needs it) and your max texture size high. I would have gone for 16 wide but most ID1 maps require 32 at some point, so 32 it is. This lets me pack in a LOT of surfaces sharing the same texture into the same lightmap, meaning better batching and less state changes.

They are also updated directly as modifications come in, rather than having the update deferred until all modifications are done, then bulk-updated. The latter can be faster in optimal cases, but the former avoids having a large dirty rectangle, much of which might not have been modified at all, so in the real world it's quite a bit faster.

Texture chains are dead and have been removed from the engine. Texture sorting for each model now only happens at load time; an initial qsort of surfaces by texture, then I have my filthy way with them (allocating lightmaps and triangle lists in texture order), then I qsort them again by number to put them back into the correct order.

The tall-but-narrow approach should also be viable in GLQuake. Just change some #defines, say BLOCK_WIDTH goes to 64 and BLOCK_HEIGHT to 256 and see what happens. You could also try 32 and 512 if you're not concerned about supporting 3DFX cards.

0 comments: