How can I learn the different blending types? (eg. additive, solid, alpha, etc...)

Started by
4 comments, last by sofakng 16 years, 11 months ago
I'd like to create a simple 2D game and it seems like "blending" type is very important. If I understand correctly, the blending is used to determine what to do if you're drawing on top of existing pixels. (eg. drawing a blue quad on top of a red quad). I'm not sure which API I'll be using (OpenGL or DirectX), but I was wondering if any really in-depth tutorials (or examples) exist for teaching me the differences between them (and tips on when to use each type). Thanks... - John
Advertisement
In the recent DirectX SDK versions there is a tutorial called "Tutorial 14: State Management" that goes over quite a bit about the differences in blending, culling, stenciling and other things having to do with device state changes. The documentation with the tutorial is also very easy to understand. The app itself allows you to toggle a bunch of different states and blend functions to see the results.

You can grab the latest SDK version here.

Hope this helps.
Blending is one of the most simple, and yet most-oft confused concepts in graphics. It simply determines what happens when a fragment (pixel, color) is to be drawn to the screen (texture, wherever).

The equation used is:

Result = Source * SourceFunction + Destination * DestinationFunction

That's it!

Result is the final color output to the screen.
Source is the "new" color that has been generated.
Destination is the color that was previously in the framebuffer at that location.

The two functions are what makes it so powerful, and make it actually useful.

Some functions include:
One, Zero, Source Alpha, One Minus Source Alpha, etc (look them up!).

Basically, by specifying the correct functions, you can create a variety of blending effects. If you specify, for example, One for your SourceFunction, and Zero for your DestinationFunction, the equation simplifies down to:

Result = Source

Basically, no blending at all!

Specifying (One, One) (One for the SourceFunc and One for the DestFunc) will give you:

Result = Source + Destination - additive blending! The two colors will be added together to give the final result color!

Transparency can be done using (One, One Minus Source Alpha) - the equation becomes

Result = Source + (1 - Source.A)*Destination - the amount of color that shows through the new fragment is scaled by the alpha value of the source texture. If you specify your source color from a texture, you can use the texture's alpha channel to determine how much "light" to let through!

Basically, I suggest you look up the different functions you can use (there are really only a small number of them), and work out the math so you can see exactly what is being accomplished.
Thanks for the very helpful information!

If I understand correctly,

One = The color just as it is
Zero = Don't use any color

So...

Source (Zero) + Destination (One) = Destination just as it was before [eg. no change, aka pointless??]

Source (One) + Destination (Zero) = The source just as it is and ignore what was previously there

Thanks again for the help!!
Just an extra note. You can change the + in the middle of the equation. In D3D it's D3DRS_BLENDOP. You can use subtract(src-dest), revsubtract (dest-src), min, and max.

Also, in D3D9, some cards allow you to blend the alpha seperately with it's own blending options, which can be useful in some cases. (Only useful if you've made a backbuffer or render target that contains alpha bits).
Wow... it seems like there is a metric crap-load of different ways to blend colors together.

Even after I understand what is going on for each different blending operation, how in the world would I know when to use them? Right now I can understand how alpha-blending could be used, but I have no idea for the other modes. It seems like each of them is for creating special effects? (but how do you even begin to realize what the special effect will look like unless you try every single mode?)

This topic is closed to new replies.

Advertisement