- Home /
Transparency and texture atlases, shader calls affecting performance?
Hi,
I have a texture atlas which is being used for an entire level environment of an iphone game, part of that environment are trees that use transparency for the leaves. I'm trying to weigh up the performance of having less textures or less shaders on meshes.
Am I better off keeping the textures that require transparency separate from the main atlas to avoid all the other textures being slowed down by the transparency shader?
Or should I keep them all together on one atlas as the transparency shader won't affect performance on all the other textures?
Thanks.
Answer by Cheekorobbins · Jan 24, 2012 at 04:50 PM
Okay, thanks.
What do you mean when you 'move the masks from the alpha channel, to somewhere else.'
Do you mean create a separate png/other image file just for the mask as a black and white image?
Answer by Jessy · Jan 24, 2012 at 02:56 PM
Fewer textures is better. Here's what to be concerned about for the present, though: you can't use good-looking compression on images with an alpha channel, with PVRTC. (Unity 3.5 calls this the "Best" setting.) As such, I'd either split the RGBA from the RGB, so you can use better compression on the RGB areas, or, you can move the masks from the alpha channel, to somewhere else. I've personally been using the latter, with the mask in all three channels, on the RGB atlas. The result is outstanding.
Edit - You asked about "somewhere else". It could be its own image. Obviously an 8-bit mask is going to give you the best results (unless you started with an even higher depth mask, but Unity doesn't facilitate working with that yet), but it could be RGB, or any one subset of those, and that will allow for compression. You just need to pull from the right place, in your shader. There is a hit for swizzling lowp vectors on the SGX, but it's worth it for this, and you can sort of get around it by dotting the .rgb of the texture with some vec3 constant, and moving that to the alpha channel, which seems to be cheaper than moving from one RGB channel to any other channel. If you can use the same offset for all of your masks, then you can avoid having to use a 2nd UV set, for batching.
Like I said, I've used the mask in all three channels, so the result is greyscale, but I haven't checked to see if just using one channel would change the quality.