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 openphoto.net for the image of the moon.

9 comments:

  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.

    ReplyDelete
  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?

    http://books.google.com/books?id=4PxR6Nq4jqIC&pg=PA54&lpg=PA54&dq=moon+%22non-lambertian%22&source=bl&ots=UIcxUzTgEm&sig=U78FNPem-C4GE51sM40d5Z21uw0&hl=en&ei=10d2Spy9C4K0Nr-2_LAM&sa=X&oi=book_result&ct=result&resnum=1#v=onepage&q=moon%20%22non-lambertian%22&f=false

    ReplyDelete
  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

    ReplyDelete
  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: http://renderwonk.com/blog/index.php/archive/adventures-with-gamma-correct-rendering/

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

    ReplyDelete
  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!".

    ReplyDelete
  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.

    ReplyDelete
  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.

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

    ReplyDelete