The effect of quantization in gamma space and linear space

I mentioned already (here and here) that one problem with gamma correct rendering is how we lose prevision for small values, and may run out of it if we didn’t have enough of it. I wrote a quick shader to demonstrate this problem and see how severe it is depending on the number of bits.

Thanks to BeautyPi‘s fantastic tool, ShaderToy, I could put it on line. Here is the live demo with an absurdly low precision format (R5G6B5) so you cannot miss the banding; just press the play button. It displays colors with maximum and low precision, in linear space and gamma space. The lighter vertical line shows the 50% intensity position. You can see the shader and play with the values here.

Readings on color management

Color management in the production pipeline is a tough topic. A really tough one. And a crucial one too. Unfortunately not only is this an important and difficult topic, but it also seems to me that except maybe for people working on AAA games or heavy budget film industry, most have little knowledge on the matter, when they’re not just completely unaware of the issue.

The issue that image capturing devices, screens and printers all have different color characteristics (said simply: what you scan, photography or film will not look the same depending on the capturing device used, and a same image will look different depending on the display or printing device too).

The issue that they have a capturing or display range usually far from what the human vision is capable of, and by “far” you must understand by orders of magnitude (said simply, the average human can perceive way more contrast than a camera is able to capture, differentiate much more colors than a screen is able to display, and on top of that there are colors an average screen is just absolutely unable to render, like the orange of your fluorescent highlighter for example; this one is my favorite example actually :) ).

The issue that screens and image formats use a non linear representation leading to severe errors in colors unless it is taken into account when manipulating images (said simply, ignore gamma correction in your rendering and your lighting will be wrong, ignore it when you resize images and they will look wrong too).

I just wish it were more simple and “just worked”. But until then we have to deal with it. So here goes the list of readings on this nonetheless very interesting topic.

On color management:

On gamma correction:

  • Gamma error in picture scaling: this article shows how bad things can go when image manipulation softwares don’t take gamma into account, and gives a glimpse of how widespread the problem is.
  • The Value Of Gamma Compression: I like this short article a lot, as it shows in a quick a clear way how a bad gamma management can ruin a rendering.
  • Gamma and Lighting Part 1, Part 2, Part 3: this three parts article from the same blog explains how they handle the issue in the production pipeline of X-Plane.
  • GPU Gems 3, Chapter 24 – The Importance of Being Linear: this article explains how to take gamma into account in your rendering pipeline; while an interesting read, I think it doesn’t make the issue obvious enough (as I find the different illustrations to be equally bad looking).
  • Gamma FAQ: this FAQ is quite dated but still helps understanding the origin of gamma correction and avoid confusion between various concepts (there is also a Color FAQ from the same author).

Update: this 4mn video explains quite convincingly the need for gamma correction.

On tone mapping:

Have a good read!

Update: this lengthy presentation of GDC 2010 (quoting: “The presentation is basically four 20 minute presentations crammed into 55 minutes.”), by John Hable, covers several of these topics.