Page 1 of 1

Bloom

Posted: Mon Oct 07, 2013 5:37 pm
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.

Re: Bloom

Posted: Mon Oct 07, 2013 6:56 pm
by Barnes
with fbo or not?

Re: Bloom

Posted: Tue Oct 08, 2013 6:13 pm
by Vic
fbo, of course!

Re: Bloom

Posted: Tue Oct 08, 2013 9:17 pm
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.

Re: Bloom

Posted: Thu Oct 10, 2013 8:49 pm
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); 

Re: Bloom

Posted: Fri Nov 01, 2013 2:22 pm
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