Difference between revisions of "User:Clipka/Gamma"
(Created page with '== What is this Gamma Thing All About? == In short, the whole "gamma" issue is about nonlinearity in image processing, regarding how intermediate brightness levels between 0% an…') |
|||
Line 25: | Line 25: | ||
If you frequently pick colors, you may also want to define a macro to do the job: | If you frequently pick colors, you may also want to define a macro to do the job: | ||
− | + | <source lang="pov"> | |
− | + | #macro PickedRGB(R,G,B) | |
− | + | #local Red = pow(R/255, 2.2); | |
− | + | #local Green = pow(G/255, 2.2); | |
− | + | #local Blue = pow(B/255, 2.2); | |
− | + | rgb <Red,Green,Blue> | |
− | + | #end | |
− | + | ||
+ | #local MyColor = color PickedRGB(255,128,0); | ||
+ | </source> | ||
If you generally feel more at home with defining colors by pixel values rather than physical brightness levels, you can use the same macro of course for all your colors, not just those you picked from some image-editing application. | If you generally feel more at home with defining colors by pixel values rather than physical brightness levels, you can use the same macro of course for all your colors, not just those you picked from some image-editing application. |
Revision as of 20:07, 4 November 2009
What is this Gamma Thing All About?
In short, the whole "gamma" issue is about nonlinearity in image processing, regarding how intermediate brightness levels between 0% and 100% are interpreted.
To let you take a first brief glimpse at the can of worms we're about to open: A standard 8-bit image file has pixel values ranging from 0 to 255, equivalent to 0% and 100% brightness respectively. So what brightness would you expect for a value of 128? Well, 50%, right? Wrong. A meager 22% is usually closer to the mark. (Or 20%, or 25%, or whatever exactly your system happens to make of it.) Unless we're talking about perceptual brightness: A physical light intensity of 22% actually looks surprisingly bright, and an observer may percieve it as something around 45% in between black and white. Depending on ambient viewing conditions.
Why Should I Care?
Even as a POV-Ray beginner, you'll possibly care about the general phenomenon: The 50% vs. 22% vs. 45% thing - pixel values and perceptual brightness vs. physical light intensity. These differences have two major implications for you:
- Colors you pick in Photoshop (or Gimp or whatever your favorite image processing software may be) will not seem to work in POV-Ray as expected; grey-ish colors will simply appear too bright, while more colorful ones will appear washed out, or even off hue (this is because the nonlinearity affects each color component individually).
- When trying to achieve a certain brightness level, you may have difficulties getting the level right at first attempt.
As an advanced POV-Ray user, you may also worry about different systems exhibiting more or less subtle differences in the nonlinearity:
- The same image file may display differently on a friend's computer. Or the new LCD you're about to buy. Or the machine you're running your overnight renders on. Or the computers of the jurors of that internet ray tracing competition you're taking part in. You probably want to make sure they can see the barely-lit creature lurking in your nighttime scene, or that your daytime scene doesn't look too washed-out on their displays. Presuming they have done their own gamma homework of course.
- You want to be sure that the scene you share across the internet renders on the recipient's computer just as it does on your own.
So What Can I Do About Those Color Picking Issues?
When picking pixel values from Photoshop (or whatever you have), you can use the following formula to compute the color parameters to use in your POV-Ray scene file:
If you frequently pick colors, you may also want to define a macro to do the job:
#macro PickedRGB(R,G,B)
#local Red = pow(R/255, 2.2);
#local Green = pow(G/255, 2.2);
#local Blue = pow(B/255, 2.2);
rgb <Red,Green,Blue>
#end
#local MyColor = color PickedRGB(255,128,0);
If you generally feel more at home with defining colors by pixel values rather than physical brightness levels, you can use the same macro of course for all your colors, not just those you picked from some image-editing application.
Why Does POV-Ray Not Do it The Photoshop Way?
With raytracing being essentially an attempt to simulate the physical interaction of light rays with object surfaces and media, it should come as no surprise that the math behind it is easiest (and fastest) when brightness levels are expressed as physical light intensity, rather than perceptual brightness (which varies with viewing conditions anyway) or the more or less arbitrary concept of pixel values (which we'll go into detail later). To get realistic results at reasonable speed, a raytracing system must do virtually all its internal computations with physical light intensity.
Still, in theory this would not stop us from having the user specify all colors by pixel values, and automatically convert to physical light intensity just as the macro above does. So why does POV-Ray not do it?
The answer lies in the power of the scene description language: You can do too much with colors in POV-Ray's SDL that it is practically imposible to come up with a watertight automatism of identifying which non-color value specified in a scene file will wind up being interpeted as a color nonetheless (and therefore would have to be subject to conversion), which color value will end up being interpreted as a non-color (and therefore would have to be exempt from conversion), and whether some mathematical operation on colors should be performed in the pixel value domain or in the light intensity domain instead.
POV-Ray's philosophy therefore is to always presume colors to be expressed by linear light intensity values, and leave it up to the user to explicitly specify when and where conversions are to be applied.
So What Can I Do About Those System-Dependent Differences?
In a nutshell, the answer is: Calibrate your system, and encourage others to do the same.