<p>Section "17.3.8 Blending" of the OpenGL spec states:</p>

<blockquote>
  <p>If the color buffer is fixed-point, the components of the source and destination values and blend factors are each clamped to [0, 1] or [-1, 1] respectively for an unsigned normalized or signed normalized color buffer prior to evaluating the blend equation. <strong>If the color buffer is floating-point, no clamping occurs</strong>. The resulting four values are sent to the next operation.</p>
</blockquote>

<p>So we know that no clamping occurs there. The next section is "17.3.8.1 Blend Equation" and states:</p>

<blockquote>
  <p>Signed or unsigned normalized fixed-point destination (framebuffer) components are represented as described in section 2.3.4. <strong>Constant color components, floating-point destination components, and source (fragment) components are taken to be floating-point values</strong>. If source components are represented internally by the GL as fixed-point values, they are also interpreted according to section 2.3.4.</p>
</blockquote>

<p>Finally, section "17.3.8.2 Blend Functions" refers to table 17.2 which explains that for <code>GL_SRC_ALPHA_SATURATE</code>:</p>

<pre><code>RGB Blend Factors = (f, f, f)
Alpha Blend Factor = 1
</code></pre>

<p>where</p>

<p>$$ f = min(A_{s0}, 1 - A_d) $$</p>

<p>So it seems that the reference documentation is misleading for this particular case. However the specification is clear: there is no clamping or conversion for floating-point color buffers.</p>

<h3>What if Ad is negative floating value?</h3>

<p>My reading of the spec is that nothing special happens if Ad is negative. The <code>min()</code> operation will still produce results, but I don't see how they would be useful.</p>

<p>I've never used <code>GL_SRC_ALPHA_SATURATE</code> myself, but the way I understand it, with <code>GL_FUNC_ADD</code>, it is meant to accumulate color values in the color buffer until the accumulated alpha value equals 1. When the alpha value of the color buffer is 1, no further color contribution from new pixels is allowed. This assumes that you use alpha values between 0 and 1 and use an initial alpha value of 0. Otherwise everything falls apart.</p>

<p>In fact, I think majority of the blending factor mechanisms were designed with alpha values between 0 and 1 in mind and make little sense outside of that range.</p>

CC BY-SA 3.0
2017-12-09T21:31:14.340Z
I ran some test, and found that ka is 1 for all blending functions with a floating point texture, not 2^(mc)-1 as in reference page. Floating point values are not clamped and negative values are taken as it is. So you were right :)
codeKhor
CC BY-SA 3.0
2017-12-08T21:13:57.917Z
2017-12-08T21:13:57.917Z
bernie
<p>I'm confused how does the GL_SRC_ALPHA_SATURATE function effect a 32 bit floating point texture attachment in FBO while blending colors. In the <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml" rel="nofollow noreferrer">reference</a> the equation is:
<a href="https://i.sstatic.net/EDVYW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EDVYW.png" alt="enter image description here"></a></p>

<p>Here what is the value of kA for a 32-bit(GL_RGBA32F) texture?</p>

<p>According to <a href="https://www.khronos.org/opengl/wiki/Blending#Source.2C_Destination.2C_and_the_buffer" rel="nofollow noreferrer">wiki</a>, when blending a floating point texture, the color value does not get normalized. If so then does min(As, ka - Ad) get divided by the kA?</p>

<p>And lastly, what happens if Ad is negative floating value?</p>

<opengl><opengl-es>
Blending for Floating Point Texture
codeKhor
# Blending for Floating Point Texture

(Asked by: username_0 on 2017-12-08)

I'm confused how does the GL\_SRC\_ALPHA\_SATURATE function effect a 32 bit floating point texture attachment in FBO while blending colors. In the [reference](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml) the equation is:
[![enter image description here](https://i.sstatic.net/EDVYW.png)](https://i.sstatic.net/EDVYW.png)

Here what is the value of kA for a 32-bit(GL\_RGBA32F) texture?

According to [wiki](https://www.khronos.org/opengl/wiki/Blending#Source.2C_Destination.2C_and_the_buffer), when blending a floating point texture, the color value does not get normalized. If so then does min(As, ka - Ad) get divided by the kA?

And lastly, what happens if Ad is negative floating value?

**Tags:** opengl, opengl-es


---

## 1 answers

### Answer by username_1 on 2017-12-08. Score: 2 | Accepted answer

Section "17.3.8 Blending" of the OpenGL spec states:

> If the color buffer is fixed-point, the components of the source and destination values and blend factors are each clamped to [0, 1] or [-1, 1] respectively for an unsigned normalized or signed normalized color buffer prior to evaluating the blend equation. **If the color buffer is floating-point, no clamping occurs**. The resulting four values are sent to the next operation.

So we know that no clamping occurs there. The next section is "17.3.8.1 Blend Equation" and states:

> Signed or unsigned normalized fixed-point destination (framebuffer) components are represented as described in section 2.3.4. **Constant color components, floating-point destination components, and source (fragment) components are taken to be floating-point values**. If source components are represented internally by the GL as fixed-point values, they are also interpreted according to section 2.3.4.

Finally, section "17.3.8.2 Blend Functions" refers to table 17.2 which explains that for `GL_SRC_ALPHA_SATURATE`:

```
RGB Blend Factors = (f, f, f)
Alpha Blend Factor = 1

```

where

$$ f = min(A\_{s0}, 1 - A\_d) $$

So it seems that the reference documentation is misleading for this particular case. However the specification is clear: there is no clamping or conversion for floating-point color buffers.

### What if Ad is negative floating value?

My reading of the spec is that nothing special happens if Ad is negative. The `min()` operation will still produce results, but I don't see how they would be useful.

I've never used `GL_SRC_ALPHA_SATURATE` myself, but the way I understand it, with `GL_FUNC_ADD`, it is meant to accumulate color values in the color buffer until the accumulated alpha value equals 1. When the alpha value of the color buffer is 1, no further color contribution from new pixels is allowed. This assumes that you use alpha values between 0 and 1 and use an initial alpha value of 0. Otherwise everything falls apart.

In fact, I think majority of the blending factor mechanisms were designed with alpha values between 0 and 1 in mind and make little sense outside of that range.

> **Comments:**
> **username_0**: I ran some test, and found that ka is 1 for all blending functions with a floating point texture, not 2^(mc)-1 as in reference page. Floating point values are not clamped and negative values are taken as it is. So you were right :)  

---

