Bloom

Discuss programming topics that involve the OpenGL API.
Post Reply
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Bloom

Post by Vic »

Hi,

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.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Bloom

Post by Barnes »

with fbo or not?
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Re: Bloom

Post by Vic »

fbo, of course!
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Bloom

Post by Spike »

take screen
filter it so lower levels do not blur.
downsize
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.
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Re: Bloom

Post by Vic »

Spike,

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*/
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
Spiney
Posts: 63
Joined: Mon Feb 13, 2012 1:35 pm

Re: Bloom

Post by Spiney »

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
Post Reply