Wednesday, October 14, 2009

Gamma Correct Lighting, On The Moon!

When I explain gamma correct lighting to people, sometimes they look at images and aren't certain which is supposed to be better.

E.g. in GPU Gems 3, The Importance of Being Linear two spheres are shown, similar to these:

Two spheres lit by a directional light. Which has gamma correct math?

A small thought occurred to me: there's an object people are familiar with that will help them to understand, the moon:
Two spheres lit by a directional light, compared with an image of the moon.
Which has gamma correct math?

Still don't see it.. yes, it's subtle... shall we make it obvious with a gradient?

Yes, it is but one example, there are many more. But it's a good basic visual example.

If you'd like to read more on gamma correct rendering:
[EDIT: See the comments for some nice thoughts from people who've spent more time on this.

Naty points out another good example in Real Time Rendering.]

Thanks to "ComputerHotline" on for the image of the moon.


  1. Isn't the moon often used also as an example of how Oren-Nayar can produce better results than the plain old Lambertian model? I assume the above images are using Lambert, is that right?

    Either way, it's clear that the one on the right is more correct than the one on the left. It's amazing how many games I see that appear to have gotten this wrong.

  2. The moon exhibits quite a bit of backscattering, such that the area near the terminator is brighter than a normal Lambertian surface. Is the lighting model closer to standard in that photo, now that the light source (sun) is perpendicular to the view direction?

  3. I agree with the image on the right is the gamma correct rendering. Though, I disagree with your experiment.

    The moon has large facets (mountains) that reflects light back towards the person standing on the ground. The lambert BRDF you chose to render isn't representative of the moon.

    Look at Oren-Nayar for a BRDF that represents the moon better. (In fact the first commercial use of Oren-Nayar was a TV spot that had a moon in the background).

    -= Dave

  4. In the third edition of "Real-Time Rendering", we used an image that communicates this quite well, I think. You can also see it on an old blog post of mine, about a quarter of the way down:

  5. The image on the right may be more correct, but the image on the left is more appealing.

  6. I don't think that your moon analogy is very strange or wrong. Actually, when I first experimented with gamma correction, my first thought was (when viewing a gray sphere): "hey, that looks like the moon now!".

  7. Very cool, I didn't really understand the issue with gamma adjustment before. Thanks for linking to the article, and I think your moon example makes a lot of sense.

  8. It's a nice example.

    I also think there is something worth considering in Anonymous' comments that the one on the left is more "appealing".

    Without any reference to correctness, the left does have a more noticable gradient. I could argue that this pronounced gradient helps define the shape of the sphere more clearly. It's 'more obviously' a sphere. I'd suggest it also looks less like the moon, but cheating to help the perception of shape is not necessarily a bad thing.

  9. Excellent entry! I'm been looking for topics as interesting as this. Looking forward to your next post.