Gamma
Tags | graphics |
---|
Overview
The intensity of light generated by a monitor is not a linear function in terms of the applied input signal.
A gamma of 2.2 is typically used for computer monitors and televisions.
The response of a monitor follows approximately a pow(x, 2.2)
curve (red on the graph).
The horizontal axis is the original luminance of the image.
The vertical axis is the luminance of the image as it displays on a monitor.
Middle tones to darker parts of images display darker than they actually are.
Images are stored in gamma-corrected space, so that they look correct on a monitor.
The gamma-correction applied to the images cancel out the gamma-curve of the monitor, leading to a linear response.
In game development proceeds, the following problems can occur because of gamma:
- Images may not display correctly, even with correct lighting calculations.
- Light adjustments do not produce the expected results (middle tones are darker, and bright tones white out when trying to adjust the light).
Linear Workflow
The problems related to gamma can be resolved by handling images in a linear color space.
This method is called linear workflow.
In a renderer, the lighting calculations are performed in linear space, to get correct results when working with light intensities.
When the image is output from the frame buffer to the display, the frame buffer is gamma-corrected to cancel the monitor gamma.
It produces the correct output on the monitor.
Renderer
Depending on the render device, there are two ways to properly handle gamma-correction.
Textures
When loading diffuse/albedo textures, undo the gamma-correction.
- If the render device supports the sRGB format, the hardware can handle the gamma-correction.
- If there is no hardware support, undo the gamma-correction when reading from the texture in the shader program.
Frame Buffer
- When creating a frame buffer, let the hardware perform the gamma-correction.
- On Direct 3D 11, you create a sRGB frame buffer using the
_SRGB
format modifier.
- On Direct3D 9, you specify the
D3DPRESENT_LINEAR_CONTENT
flag when callingPresent
.
- On Direct 3D 11, you create a sRGB frame buffer using the
- If there is no hardware support, before storing the final color values in the frame buffer, apply a gamma-correction step in a post-processing shader.