Unity 5 - Gamma vs. Linear Colour Space

After upgrading our project to Unity 5 I thought it’s about time I get myself up to speed with Gamma vs. Linear colour space. We previously used Unity 4 Pro (and are using Unity 5 Pro).

Looking at the Unity Labs demo I notice the settings there are for the Rendering Path to be Deferred (the new Unity 5 one) and for the Color Space to be Linear.

We currently use Gamma space for our game. When swapping things over for a test I notice things generally look very different (and I’d say worse - mostly around light intensity I think). I’ve read the documentation and tried to find as much information on Gamma vs. Linear colour space but I’m still not 100% sure on it. Is it advisable to swap over to Linear these days? Is it a general trend the industry is moving towards and are there any special considerations I need to take into account (shader support?).

I presume changing over to Linear from Gamma would require tweaks to our light intensities and user interface colours (as these were two of the major differences I noticed when I did my test swap over). Anything else I should watch out for?

Thanks in advance.

I’m pretty sure all AAA games use linear color space these days and have been for a long time. I’ve been using linear color space in all my Unity projects ever since Unity 4 was released. No matter if they were 2D or 3D. It gives much more natural falloffs for point- and spot lights and I think it looks a lot nicer in general. Before I started with Unity I was already doing my renders in a linear color space in 3ds max so it felt natural for me to use linear color space inside Unity as well.

It’s not going away, it’s the correct way of doing it.

There are some information about it here:

At the bottom they mention the legacy GUI system, but I doubt you’re still using that?

I can’t give you any tips about converting an existing project from gamma to linear as I have no gamma projects. :stuck_out_tongue: Perhaps consider starting some new projects in both linear and gamma and look at the differences? The light falloffs should be immediately noticeable at least and in my opinion they look much worse in gamma space.

3 Likes

Thanks for the heads up. I had previously gone through that documentation but re-read it for the tenth time. Seems it’s the way forward between what you said and the documentation.

Looks like we’ll move over. Thanks.

Okay,

So, lets imagine for a second that electric current fed into the monitor is equal to the monitor (or pixel) brightness.
So you would expect 1.0 amount of electricity to equal 1.0 amount of pixel brightness, and 0.5 amount of electricity to equal 0.5 amount of pixel brightness… and so on.
But, that’s not how electricity works. You feed the monitor, say, 0.67 amount of electricity and get 0.58 amount of brightness out of it.
This is why we apply an S-Curve (also known as gamma space… or SRGB) into the image to compensate for this,
so the monitor will display the correct brightness (or image values).
(even though we have added a (color) curve that changes correct pixel values to wrong one.)

If, or rather, when you switch to linear color space, you keep the image with its correct pixel values, which again causes the monitor to display it incorrectly.
But the reason we do this, is because we want to do all calculations (such as light falloff, or color adjustments) with correct pixel values. At this stage we don’t care if the monitor is displaying an incorrect image, we want to do all the math on an uncorrected image.

So after we have done everything we want to do with the image (aka. render it, and adjust it with post processing),
we apply an S-Curve (gamma space) as a final step, to force the monitor to display it correctly.

Off course, since a game, usually, is a fictional image, we can instead apply our own curve in the end to make it look like we want it to look (which incidentally usually looks rather S like).

The important thing to know is that you want to preform all math in a linear space, and then adjust the image as a post filter on the camera as a last step.

2 Likes

@Kemonono : Thanks for the explanation and the advice! It helps.

@CWolf ,
switching from gamma to linear usually gives an awful result : everything looks whitish, less colorful and possibly darker. It requires time & work on all the light intensities & colors to get a good result. The main advantage is that the lighting will be much more consistent & predictable when stuff are lit by more than 1 light source. The gamma space lighting can look prettier, but it’s always more “silly” and it’s physically very incorrect… :wink:
Switching back to gamma from linear usually gives a good result right away, in case something goes awry with the linear space. Although nowadays all tools, visual fx & other stuff should work well with linear space, so nothing too bad should happen. But if you have some custom postscreen FX still not handling linear space, you will have to do some fixing & tuning.

1 Like

I would use linear space but it can cause problems with render textures in some cases. For example, I want to project a render texture taken from a minimap camera which renders the scene with a unlit shader (so the minimap is not affected by chaning light conditions). It works flawlessly with gamma, but in linear the replacement shader call is ignored completely. It seems like it is possible to modify changer code to include some kind of gamma correction, but I wasn’t able to do it.

1 Like

I also like to refer to this: https://www.allegorithmic.com/pbr-guide
Highly recommended to better understand what you are dealing with material wise.

When you are working with Substance Designer/Painter you don’t have to think about using base images in sRGB. Substance does the conversion for you automatically. Unity also converts sRGB textures to linear.

1 Like

@Cherno : Our tech demo uses a few render textures and we’ve seen some odd behaviour from it too. As it’s a tech demo I guess it’s not a big problem as we’ll probably do things differently in the later version of things. Fingers crossed at least. Thanks for your experience.

@the_motionblur : Thanks for the link. I came across that link before but I’ve also seen people say the Allegorithmic PBR looks different to the Unity PBR so they say take the info with a pitch of salt. I’ll check it out though - thanks! =).

@manutoo : Thank for the info. We definitely saw a lot of odd things (lighting etc) when changing things over today but I keep hearing it’s more realistic lighting - so guess we’ll stick it out and keep tweaking =).

You can’t just use linear without tonemapping, and ticking HDR on your camera - just pointing it out if you missed those bits.

2 Likes

While researching this issue, I was very surprised that virtualy no one seems to have experienced the same problem… Minimaps are fairly common and now with Deferred Lighting being available for everyone for free I would have suspected many more people stumbling upon this. Added note: IIRC the issue with the replacement shader being ignored only sprung up when using Deferred lighting… Which might be a mood point since most project will naturally use it over forward rendering due to the realtime lighting etc.

Allegorithmic’s default shaders inside Substance Designer and Painter look a tad different from Unity’s. But that does not invalidate any of the information given to you over the ~60 pages of PBR knowledge in the guides.

If you want to translate the color ranges to Unity’s shader use the calibration charts.

Don’t always listen to “what people say”. People sometimes like to be more negative and complicated than necesary. :wink:

1 Like

I’m not overly familiar with tone mapping so will do my research into that. Thanks for the heads up.

@the_motionblur : True, true. I’ll get a strong tea or coffee and work my way through that at a steady pace for my ‘bedtime reading’ I think =). I found the Unity calibration charts and the Standard Shader Calibration Project so will be using all those to help me too.