Gamma Correction and Linear Colour Space simplified
I stumbled on this by accident, looking up some articles on digital lighting and rendering:
- Everything you ever used to do was WRONG
- Everything you ever got out of your renderer before was WRONG
- Everything you’ve ever put into it was WRONG
(From: http://mymentalray.com/wiki/index.php/Linear_color_space)
Pretty blunt, eh? It got me interested in finding out more about gamma correction and linear colour space, but unfortunately the majority of articles assume a fairly advanced level of understanding 3d graphics software and rendering programs. So what follows is a simplified, condensed summary of the topic, as I understand it. My aim is to try and present this in a form that’s clear and practical enough for intermediate/hobbyist artists, like myself, to understand and use. It’s taken me a while to get my head around this, so bear with me.
The basic theory is this:
- 3d rendering software renders at a different gamma setting (1: linear colour space) to what your monitor is set at (2.2 on pc, 1.8 on mac). This is correct — it’s supposed to do this to get the light calculations right. But what it means is that you have to manually apply gamma correction to your rendered image afterwards (either in Photoshop, or by the rendering software itself).
- Unfortunately, a lot of people aren’t aware that their output render needs to be gamma corrected (and traditionally, the default settings don’t enable it), so instead, when they render their work, they compensate by adding more lights, and other shader “tricks”. While this is OK for most people; technically speaking, the renders are physically inaccurate (i.e. WRONG), and you’re not making the most of the renderer. You’ll will also see more visible problems when you use more advanced lighting, such as fall off.
- Furthermore, the majority of the textures you put into your renderer have already been gamma corrected beforehand (in photoshop). So what happens when you apply gamma correction to your image at the end is that it gets applied twice (before rendering, and then afterwards) — making the image look washed out. Since you only want gamma correction to be applied at the end of your rendering pipeline, it’s necessary to gamma un-correct all of your texture maps, materials, and shaders before the renderer works with them.
So in a nutshell, what you need your software to do is:
1. Input Gamma: Automatically apply gamma un-correction to your texture maps, shaders and materials beforehand, by an inverse gamma of 2.2. (i.e. 1/2.2 = 0.4545454…)
2. Output Gamma: Automatically apply gamma correction to your rendered output, thus bringing your image to the correct colour space as your monitor (2.2. or 1.8.).
The settings will vary from program to program, but at the very least you should expect to see input and output gamma settings.
If your rendering software doesn’t have any options for Gamma correction (e.g. Daz Studio 2.x), then you can still work in linear colour space, but it’s a heck of a lot harder to set up and more difficult to tell if you’re doing it correctly.
1. Input Gamma: You have to un-gamma correct everything by hand (i.e. in Photoshop). And I mean everything — textures, shaders, colours — the works. You can use an inverse gamma curve to do this, or by adjusting the input levels midpoint by 0.455 (image-> adjustments->levels…).
2. Output Gamma: Simply apply 2.2 gamma correction inside Photoshop (or equivalent), and hope for the best.
The problem with this method is in how accurate your gamma correction is. I’m still using regular Photoshop CS, and there are no explicit gamma controls. Even worse, changing the gamma via levels gives me a slightly different results to using curves, making reliability an issue.
[ EDIT: I've just discovered a more consistent and reliable way of correcting the gamma in Photoshop, using colour profiles. Essentially what you do is make a linear colour space profile with a gamma of 1.0, and then you assign this profile to your textures and renders before working on them. When you finish, you convert your render to sRGB or AdobeRGB and it does the gamma correction automatically. I'll add this section in later after I've experimented with it further.]
If that was a load - don’t worry.
It’s taken me the better part of a year to get my head around it, and in spite of that, I’m still not crystal clear on some parts.
However, I will end this by saying that understanding linear colour space and gamma is worth the effort. It might not instantly transform your images into works of art, but the lighting will at least look natural — even if your characters don’t.
Further reading:
http://mymentalray.com/wiki/index.php/Gamma
http://mymentalray.com/wiki/index.php/Linear_color_space
http://forums.cgsociety.org/showthread.php?t=305727
http://forums.cgsociety.org/showthread.php?t=610790
http://www.poserpro.net/King_Tut/Gamma/PoserPro_Gamma.html
http://www.poserpro.net/King_Tut/vids/Gamma/Poser_Pro_Gamma.htm
http://www.renderosity.com/mod/forumpro/showthread.php?thread_id=2762503&page=1