<blockquote>
<p>How does it make sense to have a half opaque object in front of a fully opaque object result in something that is not fully opaque again?</p>
</blockquote>
<p>The problem here is one of concepts. The alpha component of a color has no <em>inherent</em> meaning. It doesn't mean opaque or transparent. It's just a value.</p>
<p>It only takes on a meaning when you use it in a way that gives it that meaning. Your blending function performs linear interpolation between the source and destination colors based on the source's alpha component. One way to conceptualize this equation is to say that the source alpha represents the opacity of the source color overlaid on top of the destination color.</p>
<p>However, this understanding of your blending equation only makes sense if we assume that the destination color is <em>opaque</em>. That is, you're always blending between a possibly transparent source and a definitely opaque destination.</p>
<p>So what does the destination alpha mean in this equation? Nothing. It's just data in your framebuffer. It has no inherent meaning within the context of this blending operation.</p>
<blockquote>
<p>So how would I set up the function to produce an alpha value which stays fully opaque when blended with a fully opaque color?</p>
</blockquote>
<p>By using <a href="https://www.khronos.org/opengl/wiki/Blending#Blending_Parameters" rel="nofollow noreferrer">separate blending parameters for the alpha</a>. The RGB and A components of the output color can be processed with separate parameters (or even <a href="https://www.khronos.org/opengl/wiki/Blending#Blend_Equations" rel="nofollow noreferrer">equations</a>):</p>
<pre><code>glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
</code></pre>
<p>This will leave the destination alpha untouched.</p>

CC BY-SA 4.0
2023-05-15T14:49:30.267Z
Ok but to my understanding the resulting alpha value can be interpreted as the opacity/transparency of the image when saved to the file. So how would I set up the function to produce an alpha value which stays fully opaque when blended with a fully opaque color?
Bartolini
CC BY-SA 4.0
2023-05-15T17:10:22.410Z
@Bartolini: "*Ok but to my understanding the resulting alpha value can be interpreted as the opacity/transparency of the image when saved to the file.*" Well, that's between you and the file format you're using. That's got nothing to do with OpenGL. I'll answer the rest in the answer.
Nicol Bolas
CC BY-SA 4.0
2023-05-15T21:25:54.730Z
Thank you very much guys, I think this clears it up for me!
Bartolini
CC BY-SA 4.0
2023-05-15T00:15:56.510Z
2023-05-15T17:12:39.077Z
2023-05-15T17:12:39.077Z
Nicol Bolas
<p>I'm struggling with understanding how blending works. Here's what I understand:
when I set the following</p>
<pre><code>glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
</code></pre>
<p>then I would expect to have the following result when blending <span class="math-container">$scr$</span> with <span class="math-container">$dst$</span>:
<span class="math-container">$$
result = src.a \cdot src + (1-scr.a) \cdot dst
$$</span>
This is the blending function setup I commonly stumble upon. My problem is the following: when I have a completely opaque background, let's say <span class="math-container">$dst=(1,0,0,1)$</span>, and I render a half opaque square in front of it <span class="math-container">$src=(0,1,0,0.5)$</span> then the resulting alpha for the new color will be
<span class="math-container">$$
result.a = src.a \cdot src.a + (1-src.a) \cdot dst.a = 0.5 \cdot 0.5 + 0.5 \cdot 1 = 0.75
$$</span>
How does it make sense to have a half opaque object in front of a fully opaque object result in something that is not fully opaque again? I feel like I'm misunderstanding something, I'm glad for any help I can get.</p>

CC BY-SA 4.0
2023-05-15T14:50:30.930Z
I've seen the equations on Wikipedia, but how would I need so set up the blend function to produce the same output as the equations found in Wikipedia?
Bartolini
CC BY-SA 4.0
2023-05-18T04:28:23.560Z
I once wrote a [lengthy answer](https://computergraphics.stackexchange.com/a/11056/8009) about how to compose blending operations.
Wyck
<opengl><blending>
How is the alpha value treated when blending?
Bartolini
# How is the alpha value treated when blending?

(Asked by: username_0 on 2023-05-14)

I'm struggling with understanding how blending works. Here's what I understand:
when I set the following

```
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

```

then I would expect to have the following result when blending $scr$ with $dst$:
$$
result = src.a \cdot src + (1-scr.a) \cdot dst
$$
This is the blending function setup I commonly stumble upon. My problem is the following: when I have a completely opaque background, let's say $dst=(1,0,0,1)$, and I render a half opaque square in front of it $src=(0,1,0,0.5)$ then the resulting alpha for the new color will be
$$
result.a = src.a \cdot src.a + (1-src.a) \cdot dst.a = 0.5 \cdot 0.5 + 0.5 \cdot 1 = 0.75
$$
How does it make sense to have a half opaque object in front of a fully opaque object result in something that is not fully opaque again? I feel like I'm misunderstanding something, I'm glad for any help I can get.

**Tags:** opengl, blending

> **Comments:**
> **username_0**: I've seen the equations on Wikipedia, but how would I need so set up the blend function to produce the same output as the equations found in Wikipedia?  
> **username_1**: I once wrote a [lengthy answer](https://computergraphics.stackexchange.com/a/11056/8009) about how to compose blending operations.  

---

## 1 answers

### Answer by username_2 on 2023-05-15. Score: 4 | Accepted answer

> How does it make sense to have a half opaque object in front of a fully opaque object result in something that is not fully opaque again?

The problem here is one of concepts. The alpha component of a color has no *inherent* meaning. It doesn't mean opaque or transparent. It's just a value.

It only takes on a meaning when you use it in a way that gives it that meaning. Your blending function performs linear interpolation between the source and destination colors based on the source's alpha component. One way to conceptualize this equation is to say that the source alpha represents the opacity of the source color overlaid on top of the destination color.

However, this understanding of your blending equation only makes sense if we assume that the destination color is *opaque*. That is, you're always blending between a possibly transparent source and a definitely opaque destination.

So what does the destination alpha mean in this equation? Nothing. It's just data in your framebuffer. It has no inherent meaning within the context of this blending operation.

> So how would I set up the function to produce an alpha value which stays fully opaque when blended with a fully opaque color?

By using [separate blending parameters for the alpha](https://www.khronos.org/opengl/wiki/Blending#Blending_Parameters). The RGB and A components of the output color can be processed with separate parameters (or even [equations](https://www.khronos.org/opengl/wiki/Blending#Blend_Equations)):

```
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);

```

This will leave the destination alpha untouched.

> **Comments:**
> **username_0**: Ok but to my understanding the resulting alpha value can be interpreted as the opacity/transparency of the image when saved to the file. So how would I set up the function to produce an alpha value which stays fully opaque when blended with a fully opaque color?  
> **username_2**: @username_0: "*Ok but to my understanding the resulting alpha value can be interpreted as the opacity/transparency of the image when saved to the file.*" Well, that's between you and the file format you're using. That's got nothing to do with OpenGL. I'll answer the rest in the answer.  
> **username_0**: Thank you very much guys, I think this clears it up for me!  

---

