I’m creating an editor extension and would like to know, of those of you who make 2D games specifically, how useful alpha-testing is to getting the results you want. Do you prefer to use alpha-blending (not just for purposes of being faster on mobile, but as an artistic choice?) The only use I can think of for alpha testing is having one color set aside as a mask color and not using antaliased edges on sprites? But does this really make sense when provided with 24-bit color sprites? If an editor extension supported alpha-blending but not testing would it affect you?
I’m a bit confused as to what you mean by alpha-testing. Cuz the definition as I understand it would have nothing to do with this.
The alpha test is a hardware feature that’s been around for more than a decade, maybe 2? It tests the value of the alpha channel from the source pixel and only allows that pixel to be output to the screen if the alpha value meets some criteria. For example you can only allow alpha values greater than 0 to let the pixel be drawn, meaning any black/zero alpha stops the RGB values from being output. You can compare to a threshold value and test if the alpha equals it, is greater than, less than, other than etc. Back when sprites were 2-256 colors and CPU resources were limited there was hardly ever use of alpha blending so artists had to do alpha testing, or testing against a 1-bit mask to allow sprites to have a variegated shape. Then along came faster hardware and alpha blending took over as much more flexible, supporting realtime antialiasing of edge pixels and emulating the same behavior of testing alpha to discard pixels where the alpha is zero. Yet alpha blending lets you also ‘partially allow’ pixel values by cross fading between source and destination pixels based on 256 alpha values. One possible benefit to the alpha test is for speed because it discards rejected pixel fragments early so they dont have to be blended. So in most ways alpha blending is superior. Yet there can be some uses for alpha tests, e.g. A threshold filter, but I just don’t see that it’s greatly useful for 2d games, hence mg question if whether it would be missed.
Wait, are you referring to when I had to make all my sprites on a hot pink background, then set that hot pink color to be the “alpha color”?
That was horrid! It restricted design and made graphics look choppy and pixelated.
Alpha test is slower on mobile than alpha blend, and the opposite is true for desktop. It’s a tool for job moment.
You know all those fancy dissolve AAA shaders? that’ll be your friend alpha test. Or a branch. Another reason to use our friend alpha test is that essentially it’s good for sorting as well, so it gets used on foliage a lot. It’s not very attractive though.
And frankly, its a poor choice for retro games.
I’m inclined to agree it’s old hat. And yes, the hot pink, for example, was a way to use it… because then you’d say anything hot pink gets to be transparent. I do see some benefit to it as a screenwipe where you iterate through the alpha values over a number of frames and the wipe follows the pattern.
Sure, but you can do that with a clever alpha mask then lerping through the alpha cutoff.
Yes you can reimplement it with a pixel shader. But that isn’t really my question. Who uses it and who needs it and for what?
Hippocoder’s answer is the one you’re looking for.
AlphaTest is mostly used in 3D games rather than 2D games, because it has the advantage of not requiring sorting. This makes it great for foliage and other geometry that requires transparency and is often clustered together in layers or intersecting other transparent elements.
It may have you thinking of the “old school” method of getting transparency from sprites, where everything was indexed palettes and so had no image alpha, but that wasn’t one of the better aspects of the good old days.
That’s not to say I never use AlphaTest, I do, but only when the situation calls for it. Say one thing about game development, say every day is different.
At the end of the day, AT shaders are pretty no-frills, and besides which you’ll find you can’t make a shoe that fits all sizes - if you’re after what 99% of people will want and use, focus on alpha blending as it actually comes with problems to solve (and that, surely, is the point of using 3rd party tools).
Now if you want to add something novel to a 2D solution, a tool for rebuilding broken pre-multiplied alphas in PNG files would be an interesting one…but that’s probably another topic
Alpha testing is very useful in 3D games. It’s almost (without insane overhead) impossible to write a decent looking leaves shader without alpha testing. The best approach appears to be to make two passes, one with alpha testing and one with alpha blending.
However, other than artistic choices I don’t really see the use of it in 2D games. The alpha blending problems you encounter with leaves (multiple parts of the same mesh overlap partially, no mesh sorting possible) don’t really apply to anything you could encounter in 2D games. However if you want to get a pixelated look alpha testing might be a nice (but by no means necessary) choice.
EDIT: It appears I’ve been too slow.
About AlphaTest on mobile :
http://forum.unity3d.com/threads/30816-AlphaTesting-unadvised-in-1.1-removed-in-2.0
Sounds like for most purposes alpha testing wouldn’t be missed at all… 6 votes in total favor so far.