2D bloom filter- problem...

Hallo, evruhbahddee. I’m working on learning to write 2D filters, and I was working on this one, and I’ve come across a dilemma. It’s a bloom filter that checks the total RGB of a pixel, puts it into a property (“brightness”), and then checks if that property exceeds a certain amount (we’ll call this threshold). If it does, it is SUPPOSED to add a halo around the area by sampling the renderTexture, and then setting up an array around the pixel, thus creating a halo. I’m not sure if I’m describing this correctly… Most of you will see it pretty quickly. My problem is that it only adds this “halo” within the pixels that exceed the threshold, and not around, thus more or less just whiting out the pixels above the given threshold.

uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;

const int NUM_SAMPLES = 2;

vec4 origcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);

void main()
    vec2 texCoo = gl_TexCoord[0].st;

    vec4 sample = vec4(0.0);
    float brightness = (origcolor.r + origcolor.g + origcolor.b) / 3.0;
            if (brightness >= 0.5)
                for(int i=-NUM_SAMPLES; i <= NUM_SAMPLES ; i++)
                   for(int j=-NUM_SAMPLES; j <= NUM_SAMPLES ; j++)
                       vec2 offset = vec2(i, j) * 0.01;
                       sample += (texture2D(bgl_RenderedTexture, texCoo + offset));

gl_FragColor = sample + origcolor;
gl_FragColor.a = 1.0;

Yes, I realize that this would create a VERY strong bloom as it’s not divided out. Right now I’m just troubleshooting this bit. Thanks! Any help appreciated.

You probably would rather want to sample the color of the whole area, and then divide that by the number of samples to get the total brightness of the bloom sample area. If the value exceeds your desired amount, then add the bloom sample color (divided) to the original color.

I see. I hate to ask, but how might I sample the certain areas…?

My mistake, I thought I had done this before, but on reading your post more thoroughly, I find that I was doing something else entirely. Very sorry about this - maybe someone with more experience in 2D filters can help you moreso.

EDIT: If you wanted to, you might be able to do a ‘pre-check’ texture2D() call to see if the color’s bright enough already, and if so, add it to the sample variable you have above. It would be doubly expensive, though.

Aye. Well, thank you… I think I see where you’re going with this. Look into it I shall!