Discuss programming topics that involve the OpenGL API.

Moderator: InsideQC Admins


Postby Vic » Mon Oct 07, 2013 5:37 pm


can anyone here provide me examples of _good_ bloom code? By good I mean reasonably optimized, well written C/C++ and modern GLSL code that produces quality picture? There are plenty tutorials on the web but somehow nothing has yet satisfied my taste :P Any clues would be appreciated.
User avatar
Posts: 17
Joined: Sun Nov 07, 2010 12:42 am

Re: Bloom

Postby Barnes » Mon Oct 07, 2013 6:56 pm

with fbo or not?
User avatar
Posts: 217
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow

Re: Bloom

Postby Vic » Tue Oct 08, 2013 6:13 pm

fbo, of course!
User avatar
Posts: 17
Joined: Sun Nov 07, 2010 12:42 am

Re: Bloom

Postby Spike » Tue Oct 08, 2013 9:17 pm

take screen
filter it so lower levels do not blur.
smudge it horizontally (yay 2d guassian blur)
smudge it vertically
repeat about 3 times
add each layer over your original scene.

guassian blur can be achieved with 3 samples:
0.3125*sample[x-1.2] + 0.375*sample[x] + 0.3125*sample[x+1.2]
the 1.2 and numbers give you a result equal to 1 with a 5-pixel-wide kernel thanks to GL_LINEAR sampling.
you can smudge it in one pass if you want 9 lookups instead of 6+a write I suppose. separate directions means you can scale up the kernel size a bit more easily without squaring the number of lookups, but hey, your implementation your code.
the downsize part allows your smudging to spread further away.

that's what fte does. only stuff above the threshold gets blured. the downsizing stuff is meant to average each pixel rather than just dropping random ones to avoid random flickering.
the spread is pixel-based, which limits the distance bloom spreads. at higher resolutions, you might need to increase the number of downsize iterations, which is a significant annoyance. As I only use a fixed iteration count, the speed doesn't drop too exponentially with higher resolutions, but stuff doesn't spread so far either.

I'm sure there's other ways to do it.
Posts: 2853
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Bloom

Postby Vic » Thu Oct 10, 2013 8:49 pm


thanks, I'll take a look at fteqw sometime soon.

P.S. Love code comments such as this one:

Code: Select all
/*top level uses nearest sampling*/
User avatar
Posts: 17
Joined: Sun Nov 07, 2010 12:42 am

Re: Bloom

Postby Spiney » Fri Nov 01, 2013 2:22 pm

Bad bloom is a pet peeve of mine, though it's gotten a lot better over the last couple of years.
Use multiple iterations like Spike said, it makes a huge difference visually.
Blur during downsampling to avoid pixelation, reduces crawling pixels when moving around.
Bluring with small kernel size during upsampling reduces the 'bilinear-look', incase you can afford it.
Don't use straight addition in LDR, it blows out stuff and creates garish colors, prefer 'screen' blending or something similar.
Subtract unblurred frame from blurred for certain things (eg. sky lighting spilling over edges).
Google for "Kawase" light streak filter for filter with a less uniform look.
You can select brightest pixels in low res buffer and splat pointsprites (inferring color).
Don't overdo it :P
Posts: 63
Joined: Mon Feb 13, 2012 1:35 pm

Return to OpenGL Programming

Who is online

Users browsing this forum: No registered users and 1 guest