UI that was originally created when using Gamma space does not appear correctly when switched to Linear space. In
particular, it seems to be a problem with how Unity treats the alpha channel differently in Gamma and Linear space.
In Linear space, all the alpha values are much higher, causing sprites to appear more opaque than intended.
The last section of this article (Unity - Manual: Color space) seems to imply that these kind
of issues can be avoided by setting UI textures to “Bypass sRGB Sampling” in the texture importer when in Linear
space; however, this not only failed to fix the problem, but it introduced a new one. When our UI textures are set to
“Bypass sRGB Sampling” the alpha problem remains, but also the colors become much brighter than they originally were. How do we solve this?
So what we are seeing is actually intended behavior, even though it really may not seem that way. Let me explain.
*The first issue is the bypassing of sRGB sampling. This should only be used for legacy IMGUI. IMGUI renders AFTER scene rendering when linear rendering has been disabled, so we need to mark the texture to not be linearized on sample. Your UI is rendered in the world so this is not applicable here. This may be changing for 5.0.
*When switching to linear mode it (greatly) changes how blending works, this is because when sampling only the rgb channels are linearised as it is assumed the alpha is a linear scale representation already. That’s just how it’s designed (http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html). This is all well and good for normal scene rendering, but it does cause some issues when it comes to UI. Essentially whats happening is that alpha is getting pushed out because it is assumed to be in linear when it’s been authored in gamma space. If you take a look at this link you can see that when alpha blending gamma vs linear the results are quite different:
linear thingy - Google Sheets Feel free to input your own values and have a play.
The issue is basically that the content has been authored for gamma blending but not linear. There are two ways this can be fixed:
- Reauthor the content for linear blending (this is supported in photoshop).
- Add a workaround in the shader if in linear space to ‘pretend’ the alpha from the source texture is in the correct format. An example of how to do that is here (http://hastebin.com/webexacepa.avrasm). This workaround requires Unity 5.