Difference between revisions of "Gamma Correction"
m |
m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | __NOTOC__ | + | __NOTOC__ __NOEDITSECTION__{{ContentBlock|color=white|content={{!!}} |
− | |||
− | = | ||
− | |||
Being aware of and respecting gamma is essential for achieving superior rendering quality. Proper gamma correction and color management is an essential part of movie production and has become common in high profile games as well. Although basic gamma correction is easy to do, it can be pretty confusing at first for artists and even graphics programmers that have not dealt with it before. | Being aware of and respecting gamma is essential for achieving superior rendering quality. Proper gamma correction and color management is an essential part of movie production and has become common in high profile games as well. Although basic gamma correction is easy to do, it can be pretty confusing at first for artists and even graphics programmers that have not dealt with it before. | ||
− | + | == Gamma Facts == | |
* CRT monitors have a non-linear response curve (rather exponential), hence an RGB value of 0.5/0.5/0.5 will not produce the expected gray of 50% brightness but rather about 25% | * CRT monitors have a non-linear response curve (rather exponential), hence an RGB value of 0.5/0.5/0.5 will not produce the expected gray of 50% brightness but rather about 25% | ||
Line 13: | Line 10: | ||
* sRGB is not a different image format, it only defines how the color intensities stored in an image should be interpreted | * sRGB is not a different image format, it only defines how the color intensities stored in an image should be interpreted | ||
− | + | == Correcting Input Gamma == | |
Most standard color textures (albedo/diffuse maps) are in gamma space (usually sRGB space) to make best use of the available 8 bits of precision. Photos are almost always in sRGB space (jpegs are corrected for a gamma of 2.2 by convention) and if you paint a texture using a standard graphics editor, it will inherit the gamma of your monitor. This is good to reduce banding artefacts but the problem is that most lighting computations done in the shaders assume linear values. For that reason, textures in sRGB space need to be linearized before being used in shaders. | Most standard color textures (albedo/diffuse maps) are in gamma space (usually sRGB space) to make best use of the available 8 bits of precision. Photos are almost always in sRGB space (jpegs are corrected for a gamma of 2.2 by convention) and if you paint a texture using a standard graphics editor, it will inherit the gamma of your monitor. This is good to reduce banding artefacts but the problem is that most lighting computations done in the shaders assume linear values. For that reason, textures in sRGB space need to be linearized before being used in shaders. | ||
Line 31: | Line 28: | ||
Note that usually only color textures (photos or hand-painted images) are stored in sRGB space. Textures that contain non-color data (like normal maps) should be in linear space and no conversion is required when they are sampled in the shader. Hence these textures should '''not''' be tagged as sRGB. It is also important to know that the alpha channel of an sRGB texture is always considered to be linear and is not transformed. | Note that usually only color textures (photos or hand-painted images) are stored in sRGB space. Textures that contain non-color data (like normal maps) should be in linear space and no conversion is required when they are sampled in the shader. Hence these textures should '''not''' be tagged as sRGB. It is also important to know that the alpha channel of an sRGB texture is always considered to be linear and is not transformed. | ||
− | + | == Correcting Output Gamma == | |
Before the final rendered image gets displayed on the monitor, it has to be converted from linear space to sRGB. This conversion can easily be done in a post-processing shader by raising the linear color to the inverse gamma exponent: | Before the final rendered image gets displayed on the monitor, it has to be converted from linear space to sRGB. This conversion can easily be done in a post-processing shader by raising the linear color to the inverse gamma exponent: | ||
Line 85: | Line 82: | ||
Finally, please note that the overlays are often drawn after the HDR post processing and would hence not be gamma corrected. Since overlays are usually just displayed without any further shading computations, a simple trick is to avoid tagging them as sRGB. Although this is logically not quite correct (overlays are color textures), it will avoid the conversion to linear space and hence also the need to convert from linear back to sRGB. | Finally, please note that the overlays are often drawn after the HDR post processing and would hence not be gamma corrected. Since overlays are usually just displayed without any further shading computations, a simple trick is to avoid tagging them as sRGB. Although this is logically not quite correct (overlays are color textures), it will avoid the conversion to linear space and hence also the need to convert from linear back to sRGB. | ||
− | + | == Final Words == | |
− | If you don't do any gamma correction, the effects of wrong input and output gamma will | + | If you don't do any gamma correction, the effects of wrong input and output gamma will '''almost''' cancel out each other and the result will look acceptable. However, the emphasis is on "almost". There will definitely be some visual glitches which are unpleasing if you aim for a high visual fidelity. |
If you have not considered gamma before and try to switch to a fully gamma aware (production) pipeline, chances are high that some brightness values like the intensity of light sources or particle colors need to be reduced. This is because without output gamma correction, everything looks darker than it actually is, and you had to adjust your light sources to compensate for that. | If you have not considered gamma before and try to switch to a fully gamma aware (production) pipeline, chances are high that some brightness values like the intensity of light sources or particle colors need to be reduced. This is because without output gamma correction, everything looks darker than it actually is, and you had to adjust your light sources to compensate for that. | ||
− | + | == Further Reading == | |
* [http://www.weltenbauer.com/upload/dateien/gamma_correct_v12.pdf Be gamma correct] (a relatively untechnical introduction) | * [http://www.weltenbauer.com/upload/dateien/gamma_correct_v12.pdf Be gamma correct] (a relatively untechnical introduction) | ||
* [http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html GPU Gems 3, The Importance of Being Linear] | * [http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html GPU Gems 3, The Importance of Being Linear] | ||
* [http://download.microsoft.com/download/b/5/5/b55d67ff-f1cb-4174-836a-bbf8f84fb7e1/Picture%20Perfect%20-%20Gamma%20Through%20the%20Rendering%20Pipeline.zip Picture Perfect: Gamma through the Rendering Pipeline ] | * [http://download.microsoft.com/download/b/5/5/b55d67ff-f1cb-4174-836a-bbf8f84fb7e1/Picture%20Perfect%20-%20Gamma%20Through%20the%20Rendering%20Pipeline.zip Picture Perfect: Gamma through the Rendering Pipeline ] | ||
+ | }} |
Latest revision as of 17:47, 3 January 2010
Being aware of and respecting gamma is essential for achieving superior rendering quality. Proper gamma correction and color management is an essential part of movie production and has become common in high profile games as well. Although basic gamma correction is easy to do, it can be pretty confusing at first for artists and even graphics programmers that have not dealt with it before. Gamma Facts
Correcting Input GammaMost standard color textures (albedo/diffuse maps) are in gamma space (usually sRGB space) to make best use of the available 8 bits of precision. Photos are almost always in sRGB space (jpegs are corrected for a gamma of 2.2 by convention) and if you paint a texture using a standard graphics editor, it will inherit the gamma of your monitor. This is good to reduce banding artefacts but the problem is that most lighting computations done in the shaders assume linear values. For that reason, textures in sRGB space need to be linearized before being used in shaders. It is easy to have Horde3D do that linearization automatically. All you need to do is indicating which textures are in sRGB space and enabling the engine option SRGBLinearization. To tag a texture as sRGB, you can add sRGB="true" to the corresponding sampler definition of a material, as shown below:
Note that usually only color textures (photos or hand-painted images) are stored in sRGB space. Textures that contain non-color data (like normal maps) should be in linear space and no conversion is required when they are sampled in the shader. Hence these textures should not be tagged as sRGB. It is also important to know that the alpha channel of an sRGB texture is always considered to be linear and is not transformed. Correcting Output GammaBefore the final rendered image gets displayed on the monitor, it has to be converted from linear space to sRGB. This conversion can easily be done in a post-processing shader by raising the linear color to the inverse gamma exponent:
Linear color values should not be stored in 8 bit render targets since otherwise precision for the darker colors will get lost, resulting in noticeable banding. A 16 bit floating point render target, which is useful for HDR as well, should be used instead. The following sample shows a basic HDR pipeline, where the gamma correction is applied after the tone mapping:
The #ifdef makes it possible to control the gamma correction from the application by configuring the shader preambles:
Finally, please note that the overlays are often drawn after the HDR post processing and would hence not be gamma corrected. Since overlays are usually just displayed without any further shading computations, a simple trick is to avoid tagging them as sRGB. Although this is logically not quite correct (overlays are color textures), it will avoid the conversion to linear space and hence also the need to convert from linear back to sRGB. Final WordsIf you don't do any gamma correction, the effects of wrong input and output gamma will almost cancel out each other and the result will look acceptable. However, the emphasis is on "almost". There will definitely be some visual glitches which are unpleasing if you aim for a high visual fidelity. If you have not considered gamma before and try to switch to a fully gamma aware (production) pipeline, chances are high that some brightness values like the intensity of light sources or particle colors need to be reduced. This is because without output gamma correction, everything looks darker than it actually is, and you had to adjust your light sources to compensate for that. Further Reading
|