I've changed colormapping for player skins; this is something I had worked on before (with mixed success) and had always meant to revisit now that I'm on shaders-only. Under the new method, a "colormap" texture is extracted from the original skin (as defined in the MDL) and colour changes are carried out entirely on the GPU.
So what does it look like? Roughly something like this:
The red channel is a multiplier for the base skin, the green channel for the shirt colour and the blue channel for the pants colour. This doesn't mean that you'll get a green shirt; the shader extracts an intensity value from each channel and multiplies that by the selected colours.
There are a number of interesting, and some quite cool, consequences of this change:
- Colour changes no longer require a texture upload. This completely eliminates any hitching or stalling when somebody changes colour, and makes it impossible for a malicious player to affect your game by repeatedly changing colour.
- Drawing the player model is moderately slower owing to a slightly more complex shader; that's the tradeoff. You shouldn't notice this at all in general gameplay though.
- Colours are subtly different owing to different gradations in shade. Modulating a greyscale image by a fixed colour can never be the same. You won't notice this unless you do an exact pixel-by-pixel comparison in an image editor though. (Yeah, another part of the tradeoff.)
- External textures will now work on the player model, and will even get the correct shirt and pants colours. Note that the mask areas for shirt and pants are still extracted from the original 256-colour skin, though. (That's required as there are specific palette ranges used for them).
- Not needing to store a separate texture for each player has resulted in some video memory saving.
- There's an interesting content bug (or maybe it's intentional?) in the original player skin: parts of the axe, some pixels on the player's face, and the soles of his boots also get colour changes. I've cross-checked this with the old way and confirmed that it happens there too.
- Animating skin groups will work with the player model, and it's possible to have different mask areas for each skin in the animation.
- It will eventually be possible to extend this colormapping to other models, but for this version of the code I'm leaving it as "progs/player.mdl" only.
- You can load an external texture defining custom mask areas (and even blend the colours for shirt, pants and base in some areas): the naming convention is: "progs/player.mdl_0_colormap.tga".
I'll probably put a second test build, containing this and the other recent changes, up tomorrow.