Author: Lui
Project: OGRE Add-on Project (HDRlib)
Type: OGRE Library
Sources: OGRE Addons SVN
Supported Platforms: Mac, Linux, Windows

This addon offers a library for HDR Rendering in Ogre. The complete functionality is in the HDRCompositor Class, that can be easily used by every Ogre Application.

To see it in action, get the whole demo: OgreHDR.rar

  • IMPORTANT NOTE go to this thread as there is a big bug with the demo code. It's a simple fix until the demo file is updated (edit by Vectrex)

Ogre forum thread

  • IMPORTANT NOTE2 When building the demo yourself there might be messages of shader synthax errors in the ogre.log. This can be solved by building the SDK source with the latest version of the DirectX SDK.

How to use

"HDRCompositor.h" and "HDRCompositor.cpp" have to be added to the project and the folder
"media/HDRCompositor" has to be added to the ressources.

To apply HDR Rendering to a scene, an instance of the HDRCompositor has to be created, at best in
the FrameListener. All Parameters can be set at any Time. If Luminance Adaptation is used, the elapsed time has to be passed to the HDRCompositor every frame for a correct calculation.

void HDRFrameListener::SetupHDRCompositor(void)
     mHDRComp = new HDRCompositor(m_Window,m_Camera);
     //Set parameters

For the Scene it's very important that all used materials are at least Pixel-Shader 2.0, otherwise the floating point render target gets corrupted. Thereby are some known problems with Stencil Shadows and Shadowmaps.

For further details look at the Demo-Source.


The HDRCompositor uses the OgreCompositor to create a HDR post-processing effect by
the given parameters. Parameters like the Key and the Glare/Star Strength just set some
shader constants, all other require to build a new compositor chain.


  • ToneMapper: Sets the tonemapping operator.
  • GlareType: Currenty only enable/disable implemeted.
  • GlarePasses: Number of gaussian filter passes, indicates the size of the glare.
  • GlareStrength: The factor with which the glare pass is blended in the final framebuffer.
  • StarType: Currenty only enable/disable implemeted.
  • StarPasses: Number of filter passes, indicates the size of the streaks.
  • StarStrength: The factor with which the star pass is blended in the final framebuffer.
  • AutoKeying: Enables the automatically calculation of the key from the scene luminance. This needs to be adapted for every scene -> "AutoKey.psh"
  • Key: The key used when AutoKeying is disabled. It indicates the average birthness of the output image.
  • LumAdaption: Enable to use temporal adaptation of the scene luminance, which is a simple simulation of the adaptation of the human eye.
  • AdaptationScale: Indicates how fast the adaptation is done.


  1. The Scene is rendered in an floating-point surface.
  2. Downsample the Scene by 4, for further processing.
  3. Calculate the logarithmic average of the scene luminance from the downsample.
  4. Calculates an automatic key-value for the scene.
  5. Render a Brightpass from the downsample. (if star or glare is enabled).
  6. Render Glare by bluring the Brightpass.
  7. Render Star by mereging an horizontal and vertical blur of the Brightpass.
  8. Draw the final Scene with selected Tonemapper and add the optional Glare and Star to the output.

Tonemappers in Detail

The implemented tonemappers are declared in "hdrchain.material".



Its the simplest and fastest way to map an HDR image, but this far away from real tonemapping. The complete HDR is just scaled to LDR. The contrast in dark regions is lost, but the colors are still strong.

Color *= Key / avgLuminance



This tonemapper scales a high luminance by 1/L and low by 1, so it has a good contrast, but on the other side colors tend to shift to grey.

Color *= Key / avgLuminance 
 Color /= Color + 0.5

Modified Reihards


This is a modification of the tonemapper usual Reinhards Tonemapper. The Colors look stronger.

Color *= Key / avgLuminance 
 Color *= (1 + Colorscaledlum / ( WhiteLuminance^2 )) / (1 + Color);

Local Reinhard


Adaptive Logarithmic


This tonemapper should be a good mapping for high color-ranges. It has been derived from a simple logarighmic mapping and interpolates between a log2 (good contrast) and log10 (high compression) mapping function depending on the pixel luminance. It might look good for images were you can optimize the parameters, but in a moving scene it's rather bad and the computation is more expensive. Another problem is that the original operator uses the maximum scene luminance to map the image. This causes heavy changes of the output image in an animated scene. Therefore this implementation uses an slightly modified operator:

Color = Key / log10(avgLw + 1) * log(Color + 1) / log( 2 + 8 * Color^(Color / avgLw, log(b)/log(0.5))

Key is the key value to tune the brightness of the output image.

avgLw the average scene luminance.

b is a constant parameter which affects the mapping curve and only values between 0.5 and 1 should be used.


"Photographic Tone Reproduction for Digital Images" (2002) by Erik Reinhard, Mike Stark, Peter Shirley and Jim Ferwerda

"Perceptual Effects in Real-time Tone Mapping" (2005) by Grzegorz Krawczyk, Karol Myszkowski, Hans-Peter Seidel

"Adaptive Logarithmic Mapping For Displaying High Contrast Scenes" (2003) by F. Drago, K. Myszkowski, T. Annen and N. Chiba

"Realtime HDR Rendering" (2007) by Christian Luksch