bloom shader for ati

Hello,
i’ve written a bloom shader that works on nvidia and ati cards. Heres the code:

uniform sampler2D bgl_RenderedTexture;

void main()
{
vec4 sum = vec4(0);
vec2 texcoord = vec2(gl_TexCoord[0]);
int i;
int j;
for( i= -5 ;i < 5; i++)
{
for (j = -5; j < 5; j++)
{
sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j-5, i)0.004) * 0.02 * (j +5);
}
}
gl_FragColor = sum
sum*0.010 + texture2D(bgl_RenderedTexture, texcoord);
}

I get a shader compile error on my nvidia 8600 (you just paste the script into the text window, type the script name into the 2d filter brick, and attach that to a run-once always sensor, right?)

You’d be my hero if this worked, unfortunately, I’m not even getting error messages. (remember, you can put your code between <CODE></CODE> (in between ][ of course) and it will be easier to copy and read.

peace,
-nick

Edit:
Whoops, the previous error message was my fault, I mistyped the script name in the filter actuator.

It works great now! I’ll post a screen in a few minutes = )

Thank you for this valuable resource!

Edit 2:
Here’s the screenshot I promised:
http://i33.photobucket.com/albums/d63/Ven0mSeven/bloomworks.png

The only problem is that it really slows down my framerate with bigger games. This is perfect for small games though.

Thanks again for your awesome work!

here’s another test:
http://i33.photobucket.com/albums/d63/Ven0mSeven/bloomworks2.png

Unfortunately this test was slow too. = (

Sad to hear that it is to slow, I would like to use this somewheres. Good work though!

It works just great for me. Thank you very much. …and yeah… it’s slow. Little faster when in runtime but still slow.

First bloom shader I’ve seen working on Ati !!! Good work snowcrash!

if it slow, make an on/off switch in the options (if you have menus in the game)

@Captain Oblivion: Sorry, don’t know why it’s not working on your system. I’ve tested the shader on a 8800GT with no problem.

Yes the shader is very slow, so i’ve been working on the perfomance: Now it runs with 40 fps on my radeon 3650 (15 fps faster) and looks a bit better i think.

Here is the new code:


uniform sampler2D bgl_RenderedTexture;


void main()
{
   vec4 sum = vec4(0);
   vec2 texcoord = vec2(gl_TexCoord[0]);
   int j;
   int i;

   for( i= -4 ;i &lt; 4; i++)
   {
        for (j = -3; j &lt; 3; j++)
        {
            sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * 0.25;            
        }
   }
       if (texture2D(bgl_RenderedTexture, texcoord).r &lt; 0.3)
    {
       gl_FragColor = sum*sum*0.012 + texture2D(bgl_RenderedTexture, texcoord);
    }
    else
    {
        if (texture2D(bgl_RenderedTexture, texcoord).r &lt; 0.5)
        {
            gl_FragColor = sum*sum*0.009 + texture2D(bgl_RenderedTexture, texcoord);
        }
        else
        {
            gl_FragColor = sum*sum*0.0075 + texture2D(bgl_RenderedTexture, texcoord);        
        }
    }
}

If the shader is running extremely slow make sure you haven’t used an allways sensor for the 2d filter actuator.

That’s the way i use the 2d filter actuator:

you can also make an state switch

Thank you very much, that works with my ATI X1600.


Regards

Po

can somebody post blend?? i have shader compile error on my ati hd2600, thanks!

what does it do?

thats a hot screen po…and a hot script snowcrash :wink:

Thank you very much for this script, Snowcrash! It is very useful and perfect for all ati users. The bloom was the only thing I missed on BGE.

PS : Is there a way to make it lower (less shiny)?

Yes, you can change some of the multipliers. For example you could replace the 0.25 in this line:

 sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * 0.25; 

with an 0.2:

 sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * 0.2; 

Or you could change the first for loop: Let him start at -3 and count to 3 (this will also make the shader run faster ;)).

There are many ways to tweak the shader.

The only thing I can say, and may the great filters.
The only way to continue.:eyebrowlift:

Awesome work Martinish… Could please suggest any good tutorials to study Blender 2d Filters GLSL scripting. I have been trying to make a simple object glow filter for weeks…

Can you apply the bloom effect to few objects? like only make a lamp glow? how do you do that?