3 Tonemapping problems

Hi!

I tried to add a HDR renderpath to my engine and started with tonemapping and
gaussblur. Both work fine but I have some problems:

I rescale the unclamped color values with this formula:

color_ldr = color_hdr * (1.0 / avg_lum)

I “calculate” avg_lum by downsampling the hdr image of the scene to 1x1 and reading back one pixel
with glReadPixels(0, 0, 1, 1, GL_LUMINANCE, GL_FLOAT, &lum);

If the screen is filled with white pixels (1.0f in each channel), ReadPixels returns “3.0” as avg_lum value.
Did i get something wrong, but shouldn’t this be “1.0”?
When I read back the colorvalues and convert them to greyscale
with the usual factors (~0.30, ~0.60, ~0.10) I get “1.0”.
Which value is the right one? Both versions work, but I want to
do it the correct way.

Second problem:

Imaging a scene where most of the screen is black or relativly dark, only a small spot
in the scene is lit by a blue light with the colors (0.1, 0, 0.85).
This looks ok with LDR rendering, but when I switch to HDR, tonemapping tries to adjust the
avg lum value to 1.0. Sounds good at first but this means that the all pixels get scaled with
a ridiculously high value (100 for example).
This turns the blue light (0.1, 0.0, 0.85) into a pink light (1.0, 0.0, 1.0)!!
Tonemapping is designed to convert the HDR to displayable LDR values but it doens’t seem
to work for scenes with strong lightingcontrast. Is there a way to fix this?
I tried to add the colorvalues which are greater than 1.0 to the other channels to create white spots
instead of pink spots but this is just a hack…

Third problem:

How do I combine the orginal scene with the blurred version to create these “overglow effects”?
Do I add the two textures or lerp depending on the luminance?
How should I determine where the glow should start, so that only very bright spots are rendered with
this effect. I tried all kinds of methods and none of them looked as nice as in FarCry or Unreal 3.
The ATI and Nv demos just mix them (50% each for example), but this blurs the hole screen and
destroys most of the texturing details.

Thanks in advance. :slight_smile:

  1. no idea but I guess that LUMINANCE is the sum of the 3 color components.
  2. “tonemapping” is a really complex topic, a google search on it gave a lot of PDF and papers about complex techniques (gradient compression, median of histograms etc).
    For a start what about a simple sqrt(scale) ? This will reduce the overscale effect. I guess it is better to try it with real scenes, not just a single pixel :slight_smile:
  3. for the glow to look good : scale your image range to black=0.0, max light=1.0, blur it, then a simple additive blending will do. You can adjust the alpha so that it is visually pleasing.

BTW here is a demo that looks good for HDR+glow http://www.delphi3d.net/#1 (june 7 2005)