POV-Ray : Newsgroups : povray.advanced-users : Why assumed_gamma 1.0 should be used (and the drawbacks) : Why assumed_gamma 1.0 should be used (and the drawbacks) Server Time
26 Jun 2024 09:00:25 EDT (-0400)
  Why assumed_gamma 1.0 should be used (and the drawbacks)  
From: Warp
Date: 11 Sep 2011 09:00:43
Message: <4e6cb0f9@news.povray.org>
This topic has been discussed in great length already, but perhaps I could
try a different approach at explaining why assumed_gamma 1.0 ought to produce
a physically more accurate result (as well as the practical complications that
using it causes when designing scenes).

  The main reason why assumed_gamma 1.0 ought to produce more accurate
results has to do with a physical concept called irradiance. Despite the
fancy name, irradiance is simply the amount of energy that a certain amount
of light carries. This is measured in watts per square meter (in other
words, how many watts of energy a certain amount of light carries to
each square unit of a surface).

  Now, when light hits a surface, some of it is reflected. How much is
reflected and to which direction is an extremely complicated function,
but for the sake of simplicity let's assume the following scenario:

  A fully white (rgb 1.0) light source, and a fully white (rgb 1.0) diffuse
surface, oriented so that it's facing at 60 degrees from the light source.
Due to this orientation the surface will reflect exactly 50% of the incoming
light to all directions (including the camera, of course).

  (The reason why it's exactly 50% at 60 degrees is due to the cosine law,
that says that the amount of reflected light is proportional to the cosine
of the angle of the incoming light, and cos(60) = 0.5.)

  In other words, assume that the light source were emitting 10 watts/m^2
of light. The surface would hence emit 5 watts/m^2. Hence the brightness
of this surface would be 5 watts/m^2 (ie. exactly half of that of the light
source).

  Now, how do we *draw* this surface? The problem is that the relationship
between irradiance and the brightness perceived by the human eye is far from
linear. In other words, the surface might be emitting 50% of the incoming
light, but it will not *look* half as bright as a fully-lit white surface.
In fact, rather than looking 50% gray, it will look approximately 73% gray,
because that's how the human eye perceives it.

  In other words, when we draw this surface, it has to *look* like a
73% gray rather than a 50% gray, because that's the perceived brightness
of half of the full irradiance.

  That is what the assumed_gamma 1.0 is doing. It's the reason why a "rgb 0.5"
will look about 73% gray with that setting (rather than 50% gray).

  Hence if you render for example a diffuse sphere like this, it ought to
be more accurate in terms of brightness than with assumed_gamma 2.2. (The
parts of the sphere that are facing at 60 degrees from the light source
should look about 73% gray, rather than 50% gray, if the physics are correct.)

  However, this causes a practical problem when specifying colors. Namely,
do you want the color definition "rgb 0.5" to mean "half of full irradiance",
or do you want it to mean "50% gray"? With assumed_gamma 1.0 it will mean
the former (while with assumed_gamma 2.2 it will mean the latter).

  As said, however, "half of full irradiance" corresponds roughly to about
73% perceived brightness (compared to the brightness of "rgb 1.0"). In other
words, "rgb 0.5" will *look* significantly brighter than half-gray.

  The relationship between irradiance (the absolute amount of energy that
is carried by light, measured in watts/m^2) and the brightness that is
*perceived* by the human eye is roughly logarithmic, and the exponent is
approximately 2.2. (The estimation is probably very rough, though.)

  Now, displays also have a non-linear relationship between raw pixel values
and the irradiance emitted by those pixels. In other words, a pixel with
values (128,128,128) will not emit 50% of the irradiance of a fully-white
pixel (255,255,255). Instead, this relationship is also logarithmic, with
an exponent of, curiously (although I don't know if coincidentally), 2.2
in most systems.

  What this means is that a pixel with value (128,128,128) will *look*
approximately 50% gray (even though the monitor is only sending about 22%
of the light, as measured in watts/m^2). This is actually extremely
convenient when dealing with bitmaps: There's an almost linear relationship
between pixel values and perceived brightness.

  This is the reason why image manipulation programs will use (128,128,128)
for half gray (because it certainly looks half gray, which is convenient).

  This is also the explanation of the "assumed_gamma" keyword: It is assumed
that the color was specified in an environment with gamma 2.2 (which is the
most common). In such an environment (128,128,128) does look 50% gray, and
hence if you use "assumed_gamma 2.2" in povray, the equivalent "rgb 0.5"
will also look 50% gray.

  The problem is that if you try to do this when assumed_gamma 1.0 has been
specified in povray, the result will be completely different. In that case
the colors are assumed to be linear (in terms of irradiance).

  As said, with assumed_gamma 1.0 "rgb 0.5" does not mean "50% gray", and
instead it means "half of the full irradiance" (which is approximately the
same as 73% gray).

  If you want "50% gray", you need to pre-gamma-correct the color. Basically,
you need to calculate pow(0.5, 2.2), getting you about "rgb 0.218", which
would be about 50% gray.

  Of course there are still some problems left. Most prominently, if you
want a gradient from one color to another that *looks* linear (rather than
being linear with respect to irradiance), there's currently no easy way to
achieve that, when using assumed_gamma 1.0. There are many other situations
as well, related to color maps and other such maps. This can make designing
textures a bit difficult.

  An easy way around this problem is to simply use assumed_gamma 2.2 and
accept that the end result might not be physically as accurate. After all,
the human brain is quite forgiving of such small inaccuracies, and nobody
will notice in practice.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.