Reputation: 24771
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.
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?
Upvotes: 11
Views: 5411
Reputation: 2770
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)
Upvotes: 8
Reputation: 474076
In desktop OpenGL, the fragment shader can output multiple colors, not just one. Each color is numbered, and each such number is mapped to an output buffer in the framebuffer, based on glDrawBuffers
.
Blending takes place independently between each fragment shader output color and the color currently stored in the destination image. So if you write two colors, blending would happen between the first color and its image, and then between the second color and its image.
For each blending operation, the source color is the color the fragment shader wrote to the output variable. The destination color is the color from the framebuffer image that corresponds to the particular fragment shader output (based on the glDrawBuffers
mapping). So the source color(s) come from the fragment shader, and the destination colors come from the framebuffer image(s).
Upvotes: 1