<p><em>Just turning the comments into a fully-fledged answer as it</em> may <em>prove useful to others</em>.</p>

<p>IMHO, the alpha channel should always be linear and treated as such.</p>

<p>You described blending a black quad over a white background using alpha=0.95, and mapping the result back to non-linear space. We'd expect a resulting, physical intensity value of 0.05.</p>

<p>If the non-linear space is sRGB, then a linear value of "0.05" would correspond to an sRGB value of "0.248" which, when mapped to 8-bit, is around 63 (or hex, 3D)</p>

<p>If your display is reasonably calibrated, you can verify this by creating, say, a 5x4 black image, setting one pixel to white, and then tiling that to a suitable size, e.g 200x200 pixels. Then draw a, say, 50x50 square in the middle and fill it with 0x3D3D3D. Here's an example:</p>

<p><a href="https://i.sstatic.net/cYTA5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cYTA5.png" alt="enter image description here"></a></p>

<p>If you take a few steps back from your monitor and squint, the centre grey region and the dithered outer should be almost indistinguishable, demonstrating a correct physical model. </p>

<p>The problem you are describing appears to be related to the fact that our visual system is non-linear, much as our hearing is too (though probably not with the same curve). For example, the analogue volume control on a hifi amplifier will use a <a href="http://electronics.stackexchange.com/questions/101191/">logarithmic potentiometer rather than a linear one</a> . </p>

<p>You thus 'simply' need to change your per-frame alpha non-linearly to get a <em>perceptually</em> even fade out.</p>

CC BY-SA 4.0
2018-07-10T13:09:26.740Z
2018-07-10T13:16:35.727Z
2018-07-10T13:16:35.727Z
Simon F
<p>I've been making a simple game in OpenGL, and implemented a screen fade-out using the old 'draw a black fullscreen quad and ramp up the alpha' trick. I'm doing all my shaders in linear space and using <code>GL_FRAMEBUFFER_SRGB</code> to automatically apply gamma. When fading out the screen I noticed that the alpha blending also becomes nonlinear - to fade to ~25% brightness I need to use an alpha of ~0.95. </p>

<p>I fired up Unity for comparison, and its alpha blending also seems to work this way - when rendering in linear mode most of the opacity is bunched towards the top of the alpha range. </p>

<p>Is this expected behaviour? Is it correct from a PBR point of view? It seems very unintuitive. As a workaround, to get more intuitive blending, would it be reasonable to apply gamma correction of 0.45 to the alpha channel before blending?</p>

<p>EDIT: this is the result I get after blending a .95 alpha black quad over a pure white button. It could be bad gamma on my display as Simon F suggested in the comments, but it looks a lot brighter than 5% to me.</p>

<p><a href="https://i.sstatic.net/M7Ybs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M7Ybs.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2018-07-09T08:24:58.057Z
IMHO, the alpha channel *should* always be linearand treated as such, though I've no idea what Unity is doing.

Oh!  It just occurred to me: are *you* expecting a *perceptually linear* fade-out? I.e. Over, say, 16 frames, frames 4, 8, & 12 should *look*, respectively, 3/4s, 1/2, and 1/4 as bright as the original?
Simon F
CC BY-SA 4.0
2018-07-09T08:34:17.763Z
Yeah that's what I mean. When using the gamma rendering mode that's what happens, but in linear mode it gets bunched to one end - rendering a black quad over a white one at .95 alpha gives a final pixel value of 63,63,63.
russ
CC BY-SA 4.0
2018-07-09T13:37:01.920Z
So blending a black over white with alpha=0.95 implies you want something that's only 5% of "fully bright"? 

Assuming an sRGB mapping, then 61 (i.e. hex 3D) __is__ 5% brightness. If your display is reasonably calibrated, you can verify this by creating a, say 5x4 black image, set one pixel to white, and then tile that to a suitable size, e.g 200x200 pixels.  Then draw a, say, 50x50 square in the middle and fill it with 0x3D3D3D.   Take a few steps back, squint, and they should be almost indistinguishable. (Again it relies on your monitor behaving correctly).
Maybe I should post the image.
Simon F
CC BY-SA 4.0
2018-07-10T10:47:25.557Z
RE: *"EDIT: this is the result I get after blending a .95 alpha black quad over a pure white button. It could be bad gamma on my display as Simon F suggested in the comments, but it looks a lot brighter than 5% to me."*
Ahh but our visual system is non-linear - much as our hearing is too. For example, the analogue volume control on a hifi amplifier will use a logarithmic potentiometer rather than a linear one (https://electronics.stackexchange.com/questions/101191/why-should-i-use-a-logarithmic-pot-for-audio-applications).  You simply need to change your per-frame alpha non-linearly.
Simon F
CC BY-SA 4.0
2018-07-10T11:15:22.883Z
Ok that makes sense. So a pixel value of 63 would be physically around .05 brightness on a properly calibrated monitor, but perceptually it will appear brighter. Thanks for your help.
russ
<blending><colorspace>
Alpha blending in linear colour space
russ
# Alpha blending in linear colour space

(Asked by: username_0 on 2018-07-08)

I've been making a simple game in OpenGL, and implemented a screen fade-out using the old 'draw a black fullscreen quad and ramp up the alpha' trick. I'm doing all my shaders in linear space and using `GL_FRAMEBUFFER_SRGB` to automatically apply gamma. When fading out the screen I noticed that the alpha blending also becomes nonlinear - to fade to ~25% brightness I need to use an alpha of ~0.95.

I fired up Unity for comparison, and its alpha blending also seems to work this way - when rendering in linear mode most of the opacity is bunched towards the top of the alpha range.

Is this expected behaviour? Is it correct from a PBR point of view? It seems very unintuitive. As a workaround, to get more intuitive blending, would it be reasonable to apply gamma correction of 0.45 to the alpha channel before blending?

EDIT: this is the result I get after blending a .95 alpha black quad over a pure white button. It could be bad gamma on my display as username_1 F suggested in the comments, but it looks a lot brighter than 5% to me.

[![enter image description here](https://i.sstatic.net/M7Ybs.png)](https://i.sstatic.net/M7Ybs.png)

**Tags:** blending, colorspace

> **Comments:**
> **username_1**: IMHO, the alpha channel *should* always be linearand treated as such, though I've no idea what Unity is doing.  Oh!  It just occurred to me: are *you* expecting a *perceptually linear* fade-out? I.e. Over, say, 16 frames, frames 4, 8, & 12 should *look*, respectively, 3/4s, 1/2, and 1/4 as bright as the original?  
> **username_0**: Yeah that's what I mean. When using the gamma rendering mode that's what happens, but in linear mode it gets bunched to one end - rendering a black quad over a white one at .95 alpha gives a final pixel value of 63,63,63.  
> **username_1**: So blending a black over white with alpha=0.95 implies you want something that's only 5% of "fully bright"?   Assuming an sRGB mapping, then 61 (i.e. hex 3D) __is__ 5% brightness. If your display is reasonably calibrated, you can verify this by creating a, say 5x4 black image, set one pixel to white, and then tile that to a suitable size, e.g 200x200 pixels.  Then draw a, say, 50x50 square in the middle and fill it with 0x3D3D3D.   Take a few steps back, squint, and they should be almost indistinguishable. (Again it relies on your monitor behaving correctly). Maybe I should post the image.  
> **username_1**: RE: *"EDIT: this is the result I get after blending a .95 alpha black quad over a pure white button. It could be bad gamma on my display as username_1 F suggested in the comments, but it looks a lot brighter than 5% to me."* Ahh but our visual system is non-linear - much as our hearing is too. For example, the analogue volume control on a hifi amplifier will use a logarithmic potentiometer rather than a linear one (https://electronics.stackexchange.com/questions/101191/why-should-i-use-a-logarithmic-pot-for-audio-applications).  You simply need to change your per-frame alpha non-linearly.  
> **username_0**: Ok that makes sense. So a pixel value of 63 would be physically around .05 brightness on a properly calibrated monitor, but perceptually it will appear brighter. Thanks for your help.  

---

## 1 answers

### Answer by username_1 on 2018-07-10. Score: 3 | Accepted answer

*Just turning the comments into a fully-fledged answer as it* may *prove useful to others*.

IMHO, the alpha channel should always be linear and treated as such.

You described blending a black quad over a white background using alpha=0.95, and mapping the result back to non-linear space. We'd expect a resulting, physical intensity value of 0.05.

If the non-linear space is sRGB, then a linear value of "0.05" would correspond to an sRGB value of "0.248" which, when mapped to 8-bit, is around 63 (or hex, 3D)

If your display is reasonably calibrated, you can verify this by creating, say, a 5x4 black image, setting one pixel to white, and then tiling that to a suitable size, e.g 200x200 pixels. Then draw a, say, 50x50 square in the middle and fill it with 0x3D3D3D. Here's an example:

[![enter image description here](https://i.sstatic.net/cYTA5.png)](https://i.sstatic.net/cYTA5.png)

If you take a few steps back from your monitor and squint, the centre grey region and the dithered outer should be almost indistinguishable, demonstrating a correct physical model.

The problem you are describing appears to be related to the fact that our visual system is non-linear, much as our hearing is too (though probably not with the same curve). For example, the analogue volume control on a hifi amplifier will use a [logarithmic potentiometer rather than a linear one](http://electronics.stackexchange.com/questions/101191/) .

You thus 'simply' need to change your per-frame alpha non-linearly to get a *perceptually* even fade out.


---

