HDR + many simple GLSL 2D Filters v2.0

just out of interest, all this work you guys are doing, is this all going to work with the new 3D glasses Nvidia have released? or is that all handled by the Nvidia card?

Umm a tutorial for mouse movement?
Picked first one in Google: http://www.tutorialsforblender3d.com/Game_Engine/MouseLook/MouseLook_First_1.html

I think Blender is already supporting pageflip stereo method. You “only” need 120Hz monitor and right hardware ;).

Right! time to raid the piggy bank then!!

I changed a few numbers and now have this (changed values underlined)

 
 
uniform sampler2D bgl_LuminanceTexture;
uniform sampler2D bgl_RenderedTexture;
uniform float avgL;
 
vec2 texcoord = vec2(gl_TexCoord[0]).st;
vec4 sample( in vec2 coord ) 
{
    return texture2D(bgl_RenderedTexture, coord )*0.5*texture2D(bgl_RenderedTexture, coord )*0.5*texture2D(bgl_RenderedTexture, coord )*0.5; 
}
void main(void)
{
    float contrast = <i>1.5</i>;
    float brightness = contrast*<i>0.45</i>;
 
 
    vec4 bloom = vec4(0);
 
    int j;
    int i;
 
    for( i= -<i>9</i> ;i &lt; <i>9</i>; i++)
    {
        for (j = -<i>9</i>; j &lt; <i>9</i>; j++)
        {
            bloom += sample (texcoord + vec2(j, i)*<i>0.00125</i>) * <i>0.16</i>; 
        }
    } 
 
 
    vec4 value = texture2D(bgl_RenderedTexture, texcoord);
 
 
    vec4 pow_value = pow(value,contrast);
 
 
    gl_FragColor = pow_value/(pow_value+pow(brightness, contrast+(bloom*contrast)));
}

It’s slow, but it can provide quite a boost in atmosphere with the bloom and everything compared to the origional, I took out the reliance on the relativeLuminance because it produced poor results in scenes with a darker background and lit objects.

Martinsh,

I had an idea (that may be eerily close to CD’s), but is there a floor and a ceiling to the lightness of the scene? Like, so when you look at bright lights, the dark area of the scene doesn’t get too dark and vice versa, when you look at dark parts of the scene, the light areas aren’t too blown out? Is that, in fact, the value CD has been playing with?

Thanks so much for all your work! We all really appreciate it!

@Cyborg Dragon

That looks more like a pure bloom shader :wink: and yea 9 vertical and horizontal blur samples is really slow, even on 9800GTX. So I usually use 3, or doesnt use bloom at all. Just have to wait till viewport rendering will have mipmaps, so we can use downsampled images for bloom effects.
I will make more user-friendly controls to change HDR amount, max light and max dark values, etc. so you can adapt it for your needs.

@Hunkadoodle

Hmm im not sure about floor and ceiling of the lightness… but you can change the HDR amount, if the intense light changes annoys you.

Quick introduction to HDR - High Dynamic Range. It imitates perceptual response of human visual system. Without HDR, areas that are too dark are clipped to black and areas that are too bright are clipped to white. These are represented by the hardware as a floating point value of 0.0 and 1.0 for pure black and pure white, respectively. With HDR we can extend these values from, for example -1000 to +1000, but that intense adaptation on your PC`s display can become really annoying :).
To enhance the illusion of brightness of the object, there is light bloom. It also simulates the light scattering in human lens that makes light appear to bleed over foreground objects.
I could aslo make the effect that temporary burns really bright spots in human eye retina and slowly fades away.
:smiley:

Hunkadoodle, Martinsh: On Hunkadoodle’s question I have found a solution that works in most cases and yet is able to be done without GLSL knowledge, I just use another property called range and replace the bottom part of the relativeLuminecense code with this

 
#Slow adaptation
if own.range &gt;=0.90 and own.range &lt;=1.03:
    own.avgL = (own.avgL*0.98 + avgPixels*0.02)
 
own.range = (own.avgL*0.98 + avgPixels*0.02)
 
avgPixels = own.avgL


The range property freely bounces around like the avgL property once did before the modification, I have the avgL only change in value if it’s between two certain values of the range property.

I did it this way because the avgL property was the thing that affected the HDR script, so essencially this reduces the possible range of brightness/darkness caused by the avgL property.

Martinsh
I know that it’s not much to say but : great job. Impressive.
As always.

Cyborg Dragon
Thank you for the explanations.

Man, that would be awesome! Id love to see (and use) it. :smiley:

Great work with the HDR though Martinsh, I’ve always heard about it but haven’t ever really known what its about, gave me reason to do a bit of research (there’s a good page about it on wiki)

All these shaders are great to see. I cant wait for downsampling to make all this stuff more usable. Is there someone whos planning to do it sometime?

would be nice to have gamma corrected BGE output… it’s easier to make more photorealistic look

If it does fit in at all to the development it would be much appreciated. I’m kinda hoping Blender will get some more streamlined / automatic features for handling the whole gamma and tone issue in general, but in the game engine would be great. I didn’t get around to finishing my YoFrankie level entry, but I was trying a sort of gamma corrected method by baking the lightmaps for the walls and so on then gamma correcting them. So any realtime lit objects were still non-corrected.

http://vimeo.com/2891466 - what I’m trying to say in video form.

For all of you people on ATI try this blend:
HDRATIFix.blend (954 KB)

(the pow function doesn’t like vec4’s on ati cards for some reason,
If there is a better way to fix, let me know)

With more recent builds both your and martinsh ATI fixed versions works ok.

Interesting work you are doing there martinsh.

There are some renders that do clearly have some tone mapping on them but others don’t have. In particular, the renders I attached don’t seem to have any tone mapping. So I whent and added a gamma correction of 2.2 on them. I agree with others that a very simple and efficient tone mapping such as gamma correction could be added to the process you are developing.

Not quite right. HDR is just a color representation format that allows to represent a much larger (practically infinite) range of illumination values, thus the name “high dynamic range”. It does not imitates nor attempt to imitate in any ways, the perceptual response of the human visual system. That would be the job of the tone mapping algorithm. HDR just stores the linear illumination values. But because of the much larger range of illumination values available in HDR format, it allows very sophisticated Tone Mapping algorithms that can imitate the human vision.

Without HDR, areas that are too dark are clipped to black and areas that are too bright are clipped to white. These are represented by the hardware as a floating point value of 0.0 and 1.0 for pure black and pure white, respectively. With HDR we can extend these values from, for example -1000 to +1000

Although the floating point representation would technically permit to extend illumination values in the negative range, in practive, we do not extend the values in the negative range and in theory, it wouldn’t make any sense anyways.

Concerning the dark or nearly black spectrum of illumination values, the actual advantage of HDR is that it can represent an almost infinite variation of dark values between the two darkest values that can be represented in normal image file formats. Thus, it becomes possible to increase exposure after the fact and be able to retrieve details in the shadows that were previously impossible to retrieve.

Concerning the brightest part of the spectrum, “pure white” is always relative and depends on the exposure and, in 3D scenes, the amount of light that we trow in the scene.

That said, I hope you keep developing this amazing GLSL work. It can only be extremely usefull for all Blender users.

Attachments


hmm… that was interesting read and i cant`t really disagree. i just thought im really clever after dissecting some HDR and tonemapping GPU rendering whitepapers and Wikipedia page here - http://en.wikipedia.org/wiki/High_dynamic_range_rendering.

Anyway this technique works and im satisfied with results, now I just need to tweak the code for filter amount and max/min luminance input etc.

I should let you know that when I turn on retinex my computer makes strange noises. I think it’s the graphics card. (2x 9600gt sli)

Is it possible to render the bgl_RenderedTexture with 64bit color depth? I just wonder how.

How did you do the materials for the model? Vertex Painting? Very interesting

WOW amazing! Keep it up something is coming along here,

and I like it. :slight_smile:

Update!

HDR1.4.blend (293 KB)

few new tweaks and filters:

Simplified HDR

5 - gamma correction (looks more lika a brightness filter)
6 - barrel distortion/fisheye (you can tweak parameters for different distortion effects)
7 - quick and easy depth of field ( i was doing real motionblur, but came up with this)
8 - animated screen distortion (underwater like filter)
9 - normal pass done in screen space (was required for SSGI)
0 - SSGI (not looking right due intense noise, but it is working)

Goddamnit Martinsh thats amazing! I Really like the animated screen distortion, will very be usefull for underwater levels! I made a runtime just for fun and I noticed running this in runtime is faster than playing it directly in blender !
runtime 800x600 = ~60 fps and blender ~800x600 = around 30 fps
Also I find it hilarous how the screen distortion played in blender shows the headers too XD