|
Author
|
||||
|
Related articles
|
||||
|
More in Development
|
||||
Now, if we give our alpha channel more bits, we make it possible for the alpha to have more values than just 0 and 1. This gives us wonderful, smooth, gradiated translucency, just like our coloured glass example. Imagine looking through a red pane of glass that's half-transparent at a green field: Our source (the glass) has a colour value of S{red = 1, blue = 0, green = 0, alpha = 0.5} - this is called RGBA notation, I'll let you guess why; The grass behind it is represented by D{0, 1, 0, 1} because it's completely green and also completely opaque! So, using the blending operation we described above, we get our final colour by adding S multiplied by its alpha to D multiplied by 1 - S's alpha (this is called giving the inverse of a value, subtracting it from its possible maximum value).
So, F = (S * Sa) + (D * (1 - Sa))
= (S * 0.5) + (D * (1 - 0.5)) : Substituting Sa = 0.5
= (S * 0.5) + (D * 0.5) : Calculating 1 - 0.5
= ({1, 0, 0} * 0.5) + ({0, 1, 0} * 0.5) : Substituting S and D's colours
= {0.5, 0, 0} + {0, 0.5, 0} : Multiplying out
= {0.5, 0.5, 0} : Adding the colours together
So our final value for F is {0.5, 0.5, 0}, giving us a half-red, half-green, mucky brown colour. Exactly what you would see if you looked through a red glass window at a green field, yay! Thankfully you don't have to do this type of calculation all the time, your graphics card is doing it millions of times per second for every pixel on screen, more yay!
Hopefully some of you will have realised that you need to have drawn the grass before drawing the red glass, otherwise all you'll see is the grass (if you can't figure out why, redo the calculation above and switch S and D around, to see what you get). This is called transparency ordering and is one of the nastier problems of 3D graphics, we'll get to it later after we've discussed other nifty things like Z buffering.
Other uses of blending
As I mentioned earlier, blending is done by your graphics card and defined by the blending operation you choose. The blending operation we've gone over so far is only one of many different possibilities. You define a blending operation by telling your API what values to multiply the source and destination colours by, so the operation we looked at above is blend(source alpha, inverse source alpha), this is the setting used to get "normal" transparency. Additive transparency is given by blend(source alpha, one) because we want the screen colour to be unchanged, we just want to add our source colour "on top" of it. The re-rendered blurred textures that give HDR (High Dynamic Range) effects their characteristic over-brightness are additively blended onto the original scene. You can even "subtract" colours from an image using blending!
There are many different blending values that you can play around with: Destination alpha, inverse destination alpha, source/destination colour, inverse source/destination colour, maximum, one, zero, etc. Experiment and see what kinds of effects you can create. Blending is extremely versatile, some people even use blending to achieve advanced stencil and lighting effects, all it takes is a little thinking outside the box.
|
Words from the readers
|
||||
|
No comments posted for this article yet. Have something to say? Make yourself heard below.
Have your say:
|
||||