We recently switched our project from Gamma space to Linear space to take advantage of its benefits for lighting. However, our UI looks significantly worse in Linear space.
We would like to fix this issue without re-authoring every UI texture in our game. The last section of this article from Unity seems to indicate that if you want to make your UI look like it did in Gamma space, you should be able to just set the texture to “Bypass sRGB Sampling”. However, this flag did not fix my problem; in fact, it made the UI look worse.
I have created and attached a small project to illustrate the problem. (The project was created in Unity5 beta 13, so it is not compatible with Unity4, sorry! However, I have observed this problem in Unity4 as well, so it seems independent of Unity version.)
There are six important elements on screen in the project:
- A UI icon from our game without “Bypass sRGB Sampling” set.
- A UI icon from our game with “Bypass sRGB Sampling” set.
- An alpha gradient (rgb is white, a goes from 0-1) without “Bypass sRGB Sampling” set.
- An alpha gradient (rgb is white, a goes from 0-1) with “Bypass sRGB Sampling” set.
- A greyscale gradient (rgb goes from 0-1, no a) without “Bypass sRGB Sampling” set.
- A greyscale gradient (rgb goes from 0-1, no a) with “Bypass sRGB Sampling” set.
By default, the project is set to Gamma space. Both versions of the UI icon look the same and look correct. (See attached image “GammaSpace.png”.)
If you switch the project to Linear space, you will see that the icon looks much worse. In particular, the alpha values are much higher, making the glow much more opaque than intended. If you look at the icon that is set to “Bypass sRGB Sampling”, you will see that it has the same problem with alpha, but it also has the problem of making the pink color much brighter than it should be. (See attached image “LinearSpace.png”.)
We can diagnose what is happening to the icon by looking at how the change from Gamma to Linear affects the alpha and greyscale gradients with and without “Bypass sRGB Sampling”.
If you look at the alpha gradient when switching from Gamma to Linear, you will notice they both have some kind of curve applied to them causing the alpha values to increase. I would expect that “Bypass sRGB Sampling” would make the alpha look the same as it did in Gamma. Is this a bug?
If you look at the greyscale gradient when switching from Gamma to Linear, you will notice that the gradient without the “Bypass sRGB Sampling” flag set looks the same. But the texture with the flag set has its greyscale values increased. This is the opposite of what I would expect. Is this a bug?
Can anyone confirm that this behavior is a bug, or justify why it behaves this way?
(As an aside, I have observed a bug that is less concerning, since it is easy to circumvent. When you switch the project from Gamma to Linear for the first time since launching the editor, rgb values seem to not be influenced by the “Bypass sRGB Sampling” flag at all. However if you switch back to Gamma, then back to Linear, it should appear how I described it previously. See the attached image “LinearSpace_Bug.png” for an example of what this looks like.)