Colors in Beast are always expressed and manipulated in linear color space. This may be unfamiliar to you if you are used to working with gamma-corrected colors.
Historically, gamma comes from a physical phenomenon in CRT monitors that results in a non-linear intensity. Typically, the color output by the monitor is:
where γ is generally somewhere between 1.5 and 2.5. Although this might seem like a clumsy convention, it is actually close to the inverse of how the human eye perceives light. Therefore, it is a relatively good way of encoding colors such that the bits in the pixels are used as efficiently as possible. By contrast, encoding colors in 8 bits per pixel with gamma 1 (i.e. linear colors) causes apparent banding in the darker part of the images and wastes bits in the brighter parts.
The exact value of γ is dependent on the physical properties of the screen and the color data. A good starting value is 2.2, which has become a de facto standard for PC monitors.
If gamma-encoded space is such an effective way to encode color information, why does Beast use linear space?
Firstly, the correct gamma to use may not be obvious; it may depend on the physical properties of a screen, or information encoded into an image.
Secondly (but more importantly), when you use colors encoded in gamma space your mathematical operations may not give the correct results. For example:
Doing math in gamma space can give rise to many problems, such as incorrect colors and brightness. In algorithms like global illumination, where light bounces multiple times, these errors amplify themselves.
The best way to proceed is to make sure all colors that are authored for the screen (typically what you find in an 8-bit texture or a color picked using a color picker) are converted to linear space at some point before you use them in computations, and that they are converted back to gamma space before you display them.
Exactly how to get this right depends on your game engine, level editor and lighting pipeline. You need to use correct conversion algorithms and make sure your images are encoded in formats that use their bits efficiently and preserve all information.
Another problem to consider is that gamma computations are meant only for color components between the values 0 and 1. Naively converting a gamma-corrected color component with the value 20 to linear space will give an intensity of 202.2, which is approximately 728. This may not be what the artist expected!
A good start to handling this problem is to separate intensity values from color values in your settings.
Beast expects all input colors to be expressed in linear space. Therefore, if you use gamma-corrected colors in your level design tool or editor, you need to convert those colors before you can store them in ILBLinearRGB or ILBLinearRGBA objects.
The way to convert a color from a gamma-encoded space to linear space is:
And to return from linear space to a gamma-encoded space:
Note that alpha channels are not gamma-corrected. They are always treated as linear.