HDR + Bloom Effect


Job Open: Blitz3D/C++ DLL RPLidar Programming. View Job Posting
(Posted 1 year ago) RonTek

HDR and Bloom Effect for OpenB3D

Copy and save the file as hdrbloom.frag.glsl and load as post process camera effect in OpenB3D, use with default.vert.glsl. See other post process effects like blur and toon for reference.

HDR and Bloom Effect for OpenB3D

// HDR + Bloom Effect
// OpenB3D version by RonTek
// www.blitzcoder.org

uniform sampler2D texture0;

// HDR Setting
uniform float exposure = 20.0; //default 20.0

// Bloom Settings
uniform float GlareSize = 0.002; // 0.002 is good
uniform float Power = 0.25; // 0.25 is good

void main()
{   

    vec4 texel = texture2D(texture0, gl_TexCoord[0].st);

    float Y = dot(vec4(0.30, 0.59, 0.11, 0.0), texel);
    Y = Y * exposure;
    Y = Y / (Y + 1.0);
    texel.rgb = texel.rgb * Y; 
    vec4 hdr = vec4(texel.rgb, 1.0);

    vec4 sum = vec4(0);
    int i, j;

    for(i = -4; i < 4; i++)
    {
        for (j = -3; j < 3; j++)
        {
            sum += texture2D(texture0, gl_TexCoord[0].st + vec2(j, i) * GlareSize) * Power;
        }
    }

    //HDR
    vec4 base_color = hdr;

    if (base_color.r < 0.3)
    {
        gl_FragColor = sum * sum * 0.012 + base_color;
    }
    else 
    {
        if(base_color.r < 0.5)
        {
            gl_FragColor = sum * sum * 0.009 + base_color;
        }
        else
        {
            gl_FragColor = sum * sum * 0.0075 + base_color;
        }
    }   

}
(Posted 1 year ago)

Wow! It looks great, I didn't know bloom was so simple to set up.

So obviously this is bloom not HDR, since bloom is fake HDR (which is real-time light reflections on surfaces).

I should make a more artistic scene for this, to show the effect better.

Anyway, thanks RonTek!

(Posted 1 year ago)

Thanks Mark! glad you liked it and feel free to add this as one of the examples. Yes, I agree but some engines still consider them as separate effects/setting (Torque3D for example) with hdr only there on the first part (Line 23 or 37).

That would be awesome and when I get more spare time, I could contribute some scenes or demos as well. cheers.

(Posted 1 year ago)

I finally added this to the repo, sorry to take so long, I didn't change the scene but maybe I will later. It's a nice effect but very slow, even blur2pass is faster than it. Thanks again!

(Posted 1 year ago)

Hey Mark, sure thing and that's awesome. I see and yes, it certainly does the job and I'm sure there are also other bloom code out there that should work faster. cheers.

Reply To Topic

Please log in to reply