Skip to main content
GameDev.net gamedev.net
🔒 Locked

Alphatest vs. Alphablend

Started by ssrun Aug 18, 2007 at 11:12 PM 7 replies 18k views
Original Post
ssrun
ssrun
Hi, I'm trying to get my head around this alpha transparency capability. Right now, I see that transparency can be achieved through alphatesting and alphablending. The question is what's the difference between the two and is one better than the other?
ShaunPeoples
ShaunPeoples
Rather old resource, but may shed some light:

http://www.bluevoid.com/opengl/sig00/advanced00/notes/node73.html
ssrun
ssrun
So from reading that article, I'm under the impression that they both accomplish the same thing except that alphablending is more CPU intensive since it needs to to do complex math calculations where as alphatesting is based on whether a pixel meets a certain criteria. In theory, alphablending is visually superior b/c the edges of the image is blended in to soften the look.

Also, from my own testing, I've discovered that alphablending & alphatesting both work on textured images but only alphablending will work on vertex shapes.
Zipster
Zipster
Alpha testing is a way to eliminate pixels whose alpha fails some test. Usually you set it to discard pixels with a very low alpha, since they'll have little to no visual effect on the scene and aren't worth blending into the framebuffer.

Alpha testing also allows you to do some other neat effects. Since pixels that are alpha tested away behave as if they never existed (as far as the framebuffer is concerned), you can create geometric cutouts of polygons by using alpha from a texture. They don't write to the Z-buffer either, meaning that if you disable alpha blending you don't even have to do a depth sort. This is great for rendering solid billboards (i.e. foliage, impostors, etc.).
ET3D
ET3D
Alpha blending is needed if you want translucency, not just a choice between completely opaque and completely transparent (which is what alpha testing gives you).

Alpha testing is easier to use because it throws away pixels. When alpha blending, even transparent pixels are drawn, which means Z is set for them, so they will prevent pixels from being drawn behind them even though there's supposedly nothing there. That's not a problem when alpha testing.
ssrun
ssrun
Quote:
Original post by ET3D
Alpha blending is needed if you want translucency, not just a choice between completely opaque and completely transparent (which is what alpha testing gives you).


That's a good point. It slipped my mind that alphatesting will not give translucency.
legalize
legalize
Quote:
Original post by ET3D
Alpha blending is needed if you want translucency, not just a choice between completely opaque and completely transparent (which is what alpha testing gives you).


Nit: Alpha testing is a rejection test for source pixels. Alpha blending is a combination of source and destination pixels.

You can certainly have alpha testing and partial transparency, because alpha blending is what happens to the pixels not rejected by the alpha test.

They both deal with alpha, but they are completely orthogonal pieces of functionality in the pipeline. You can use neither, either one, or both together.

[Edited by - legalize on August 20, 2007 5:22:29 PM]
ssrun
ssrun
OK legalize, so to sum up your post, when alphatesting and alphablending is used, the texture file gets run through the alphatest to reject pixels that match the color key specified in D3DXCreateTextureFromFileEx(). Once that is done, the remaining pixels are then run through the alphablend to display the final image. Is that correct?
legalize
legalize
Quote:
Original post by ssrun
OK legalize, so to sum up your post, when alphatesting and alphablending is used, the texture file gets run through the alphatest to reject pixels that match the color key specified in D3DXCreateTextureFromFileEx(). Once that is done, the remaining pixels are then run through the alphablend to display the final image. Is that correct?


Not quite. "Color key" here is only a feature of the D3DX function that loads textures from a file. There is no color key functionality in the Direct3D pipeline anywhere. What D3DX does is replace any pixels in the image data that have the "color key" color with transparent black, i.e. RGBA(0,0,0,0).

Alpha test is also independent of texturing. You could just as easily have per-vertex RGBA values as the diffuse color that are interpolated along a primitive and have the alpha test reject source pixels from the primitive.

If you look at my pipeline diagram, it shows you how to think of it. Source pixels -- no matter how they were generated -- enter the alpha test stage and are rejected if the test fails and the test is enabled. Whether or not those source pixels were created from texturing is irrelevant, although it is very common to have source pixels obtain their alpha value from a texture.

Subsequent to alpha test, the alpha blending operation happens when source pixels are combined with destination pixels into the render target. Again, this is entirely independent of texturing, alpha test, or any other optional portion of the pipeline that precedes alpha blending. Alpha blending doesn't know or care where the source pixels came from -- it just combines them with pixels in the destination render target.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.