Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
May 28, 2022
arrowPress Releases
If you enjoy reading this site, you might also want to check out these UBM Tech sites:


Gamma-Correct Lighting

by David Rosen on 02/04/10 11:52:00 pm   Expert Blogs   Featured Blogs

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.


I have been trying to avoid working on graphics recently in order to work on gameplay, but there was one feature I just had to implement. It has no performance cost, and makes a big difference in how the game looks! This feature is gamma-correct lighting. You can see the new lighting on the right side of this picture. 

You can see that the picture on the left has a harsher "CGI" look to it. To understand why this is, you first have to understand the 'gamma' curve. The gamma curve is used by digital displays to more efficiently encode color information for human perception. Here is a comparison between physically linear brightness (how many photons are emitted), and perceptually linear brightness (numerical differences correspond to perceived differences at any point). 

Adapted from the Wikipedia gamma correction article[1]
The lighting equations used for computer graphics are all based on physics, and thus assume that brightness 1.0 emits twice as many photons as brightness 0.5. However, on a computer screen, this assumption is not correct. Until very recently, there was nothing to be done about this, so we just lived with lighting that is physically incorrect. However, modern graphics cards have tools to support gamma-correct lighting, which you can see below on the right.

This is especially important for specular highlights (shiny areas). With incorrect lighting, specular highlights usually appear blown-out and hyper-saturated. To compensate, 3D artists often make specular maps that are the opposite color of the base surface, so that they cancel out and look white. However, with gamma-correct lighting, this is unnecessary; the diffuse color doesn't bleed into the specular color in the same way. You can see this by comparing the scars in the picture below. The lighting on the right is gamma-correct. 

Please ignore the glazed look in his eyes -- I will eventually add a special shader to render their surface shininess and retinal reflections.

To add gamma-correction to your game you just need to do two things -- convert textures to physically-linear space when you load them, and convert the framebuffer back to perceptually-linear space when you display it. In OpenGL you can just convert the textures with the texture_sRGB extension, and convert the framebuffer with the framebuffer_sRGB extension. These operations are free -- they use dedicated hardware, and have no performance cost. 

Bonus comparison shot!
If you are interested in learning more about gamma-correct lighting, you can read NVIDIA's "The Importance of Being Linear", Naty Hoffman's "Adventures with Gamma-Correct Rendering", or Bungie's "HDR the Bungie way".  If you have the latest alpha build of Overgrowth, you can turn on gamma-correct lighting by opening the "config.txt" file in the "Data" folder, and setting "gamma_correct" and "post_effects" to true.

Follow us on the Wolfire Blog!

Facebook iconModDB iconSteam iconTwitter iconYouTube icon

Related Jobs

Disbelief — Chicago, Illinois, United States

Junior C++ Programmer
Treyarch — Playa Vista, California, United States

AI Engineer
Build a Rocket Boy Games
Build a Rocket Boy Games — Edinburgh, Scotland, United Kingdom

Lead Animation Programmer
Build a Rocket Boy Games
Build a Rocket Boy Games — Edinburgh, Scotland, United Kingdom

Lead UI Programmer

Loading Comments

loader image