I've currently made a shader for customizing a player's kit that uses patterns packed into the R G & B channels. One of our coders also made a shader but his one uses pixel values to pick value ranges. That method has the benefit of packing more pattens etc into one texture. However I avoided it as I had thought that it would require per-pixel colour lookups rather than per channel. As we're targeting mobile we need to be very careful with shader instructions / perf costs.
So I'd like to know if it's indeed more expensive to tint areas of a texture by using specific pixel values of a mask texture (versus tinting a channel) OR if it makes little difference? I'd need to use more textures lookups in my method (maybe 1-2 extra)
Thanks.
Replies
But one thing to be aware of, the pixel-range method means you can't overlap any tints on the model. We used this technique (if I understand you correctly) to pack 3 tints into 1 channel. Was a bit limiting at times, but not too hard.
On the other hand, if you lookup a small texture, which could be completely cached. In the latter case it would not be that important.
Then it comes down to how complex the operations are. It is sometimes better to use a lookup texture if you have really complex stuff going on.
Then it depends on the hardware. Desktop GPU have other limits then laptop GPUs which have other limits then mobile GPUs.
And eventually it depends on the implementation, if the coder version needs to looksup in one of three different textures (depending on range), it could performe much differently then if the version only needs to look up in a single texture.
As coder I would try to limit the number of texture accesses first, if you only need a handful of additional instructions to process the data.
http://ericchadwick.com/img/robotrising_utility_shader.jpg
The other method would have say magenta for the stripes, yellow for the shirt etc etc (so would require the per pixel changes).
This is only for Android and iOS (mobile only). Probably targeting Mali 400 (Samsung S3) and ipad 2 / iphone 4s as the lowest end. Desktop doesn't matter.
Some other games use the same technique, and do some shader stuff where they blow up the section back to 1:1 space, and tint from there.
On one project we divided the alpha into three ranges, 0-85, 86-171, 172-255. So any pixels in 86-171 range would get tint color 2.
A nice benefit of this is you're not stuck with 1 single solid color, you can have a range of 86 greys, which get expanded back up to the black-white range and colored.
The drawback was you couldn't have any overlaps, since they all shared the same channel. But not that much of an issue, in practice.
In another project we limited it to two ranges, just to fit within the SM2 limits. Still worked great though.
Many ways to skin this beast!
A couple of issues to look out for-pixel ranges are very easy to break. Just copy pasting between channels can add noise (think changing to 16 bit didn't help-though I can't remember). Also variance between applications and col or spaces have to be accounted for.