I'm confused by exactly what this means:
When doing blending for a particular buffer, the color from the fragment output is called the source color. The color currently in the buffer is called the destination color.
(from the OpenGL wiki)
I understand what the blending equation itself is, but I do not understand quite the distinction between source color and destination color.
Can anyone provide an example or more specific definition?
Blending is the stage of OpenGL rendering pipeline that takes the fragment color outputs from the Fragment Shader and combines them with the colors in the color buffers that these outputs map to. Blending parameters can allow the source and destination colors for each output to be combined in various ways.
To render images with different levels of transparency we have to enable blending. Like most of OpenGL's functionality we can enable blending by enabling GL_BLEND : Now that we've enabled blending we need to tell OpenGL how it should actually blend.
Well it just so happens that there is a function for this called glBlendFunc . The glBlendFunc (GLenum sfactor, GLenum dfactor) function expects two parameters that set the option for the source and destination factor. OpenGL defined quite a few options for us to set of which we'll list the most common options below.
Blending operations take place between a source color and a destination color. The source color is the value written by the fragment shader. The destination color is the color from the image in the framebuffer.
To keep it short and simple:
glColor4f(...)
you set the source color of the operation.Usually, the reason why one uses:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Is because you want to use the alpha value you just supplied. You use it to multiply your current color, and then use (1 - alpha) and use it to multiply the buffer's current color in that coordinate.
Therefore, if you paint a quad with glColor4f(1.0f, 1.0f, 1.0f, 0.6f) and the buffer is filled with glColor4f(1.0f, 0.0f, 0.0f, 1.0f), the final operation will be:
(1.0f, 1.0f, 1.0f) * ALPHA + (1.0f, 0.0f, 0.0f) * (1 - ALPHA)
(0.6f, 0.6f, 0.6f) + (0.4f, 0.0f, 0.0f)
So the final color is (1.0f, 0.6f, 0.6f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With