High Dynamic Range Rendering in Irrlicht

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

High Dynamic Range Rendering in Irrlicht

Post by slavik262 »

HDR is a staple of almost every modern video game, and I bring it to Irrlicht.

A while back I showed off bloom, a simple effect that blurs the bright areas of the image to make them appear to glow. Now I present to you full HDR rendering with tone mapping.

For those of you who aren't familiar with the concept of HDR, I'll explain. Without HDR, the color space of a video game is limited from black (SColor(255, 0, 0, 0)) to white (SColor(255, 255, 255, 255)). This is quite unlike real life, as the white of paint on a wall is much, much dimmer than the light of the sky or the sun. HDR simulates real life much more closely by rendering the entire scene using floating-point render targets which are able to store a much broader light spectrum than standard color buffers.

Since your screen can still only display the low dynamic range (24-bit black to white), tone mapping is then used to scale the image back down to the screen color space. It does this by calculating the average brightness of the entire image (a "middle gray") and dividing all color values by this amount.

Put shortly and simply, the scene now mimics your eye. In darker areas, the scene adapts and things become brighter. In brighter areas, darker objects look even darker compared to bright lights. Looking at the first screenshot, we can see that the tone mapped image and the original image are fairly similar since nothing is exceptionally bright. Looking at the second image, however, we can see that the sun (which is 7 times brighter than the rest of the scene) makes everything else look much darker in comparison.

Click on each pic to view it in its full 1440 x 900 glory. :D

Image

Image

The screenshots can't really speak for HDR - you have to see the transition from darkness to light and then back again:

http://www.youtube.com/watch?v=mZXZyMTHFKg

You can also check it out by downloading it below. The source is included. Note that it requires DirectX 9.0 with Shader Model 2, though as with all but the simplest of post-processing, decent hardware is required to get > 20 fps. Anyone who wants to port this to OpenGL/GLSL can feel free to do so and post it here.

Download:
http://www.filefront.com/17272734/HDR.zip

EDIT: I compiled my Irrlicht.dll with the June 2010 DirectX SDK (the latest version). This means you need to either make sure you have the latest DirectX runtime (found at http://www.microsoft.com/downloads/en/d ... laylang=en) or you need to recompile the solution with your build of Irrlicht. Either way it shouldn't be a big deal at all.

Enjoy!
Last edited by slavik262 on Wed Sep 08, 2010 2:26 am, edited 5 times in total.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

Cool. This looks awesome! I can't believe it works with SM2.0.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

I get this Error messagebox when I launch

Code: Select all

---------------------------
Error
---------------------------
An error occurred in the following function: Graphics::Amplifier::Amplifier
The error is:
Amplifier shader couldn't be loaded
---------------------------
OK   
---------------------------
The console only outputs windows version and irrlicht version.
Graphics card : NVidia GeForce GTS 250
Working on game: Marrbles (Currently stopped).
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I think it looks great. I'm a little confused about the transition from light to dark however. If you are staring at a dark area for a long time, and you look at a bright area, it should be REALLY bright and then fade down to normal brightness. In your video towards the end, it looks like the exact opposite happens when you look at the bright nebula, are you sure you're not doing something backwards regarding that part of the algorithm?

EDIT: Ok so I suppose the sun is brighter than the nebula, my bad.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

serengeor wrote:I get this Error messagebox when I launch

Code: Select all

---------------------------
Error
---------------------------
An error occurred in the following function: Graphics::Amplifier::Amplifier
The error is:
Amplifier shader couldn't be loaded
---------------------------
OK   
---------------------------
The console only outputs windows version and irrlicht version.
Graphics card : NVidia GeForce GTS 250
slavik262 wrote:I compiled my Irrlicht.dll with the June 2010 DirectX SDK (the latest version). This means you need to either make sure you have the latest DirectX runtime (found at http://www.microsoft.com/downloads/en/d ... laylang=en) or you need to recompile the solution with your build of Irrlicht. Either way it shouldn't be a big deal at all.
Sorry for the inconvenience. Maybe I'll re-upload later with the standard Irrlicht build.
BlindSide wrote:I think it looks great. I'm a little confused about the transition from light to dark however. If you are staring at a dark area for a long time, and you look at a bright area, it should be REALLY bright and then fade down to normal brightness. In your video towards the end, it looks like the exact opposite happens when you look at the bright nebula, are you sure you're not doing something backwards regarding that part of the algorithm?

EDIT: Ok so I suppose the sun is brighter than the nebula, my bad.
The sun is the only bright part of the scene (7x brighter than the standard range). The rest of the scene is standard brightness (including the nebula, which is just part of the skybox). The reason the nebula lights back up at the end of the YouTube clip is because it's a "darker" object, so looking away from the sun and back at it drops the luminance and brings out the "darker" objects more (look at the luminance textures in the upper left as this happens). Sorry if this isn't that realistic (nebulae are probably pretty bright too); this demo was just a proof of concept for the game I'm working on. Also, I know the sun looks a little cheesy being solid yellow, but again, it was just a quick test.
Last edited by slavik262 on Wed Sep 08, 2010 11:51 am, edited 2 times in total.
Justei
Posts: 47
Joined: Fri Aug 20, 2010 11:20 am

Post by Justei »

Looks very nice :) Gonna try it out as soon as I get home!
Image
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Just a simple naming issue. Where you say "Bloom" you should say "Blur" ;) "Bloom" is a slightly diferent effect, it is just the same scene render + blur but without the tonemapping step. The effect is that all the scene blurs a little, and becomes a bit more bright. Just that. Looks great!
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

The standard definition of bloom involves running a bright pass (which only captures the brighter parts of the image), then blurring the result of the bright pass before adding it into the final image. It's not just a simple blur operation.

I'm not confused as to what bloom is. :wink:
My demo takes the original scene render, calculates bloom and adds it in, then performs tone mapping on the original render + the bloom.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: High Dynamic Range Rendering in Irrlicht

Post by robmar »

The download at Filefront.com get redirected, and even though it looks like the download is about to start, it never happens and there is no error.

Did anyone mange to download the source?
Jibreel Yahya
Posts: 10
Joined: Fri Oct 23, 2015 7:59 pm

Re: High Dynamic Range Rendering in Irrlicht

Post by Jibreel Yahya »

Link broken. :(
Post Reply