Light flare 2D filter help needed

Hi! I’m trying to learn to write some 2D filter scripts, because it’s pretty interesting, but I’ve just started and I’m terrible at it. I’ve written this script thus far, composited from a couple of other scripts plus some of my own writing… Most of it’s worked out, but I can’t seem to isolate the brightest parts of the screen to only be affected by the filter… Would anyone be able to tell me how to do this? Any help would be greatly appreciated!

Here’s the script… There’s a few parts //'d out to make editing easier.


from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

filter = cont.actuators[‘my bloom’] # Get the 2D filter actuator

filter.shaderText = “”"

        uniform sampler2D bgl_RenderedTexture;

        const float THRESHOLD = 0.75;
        const float OFFSET = 0.1;
        
        vec2 texcoord = vec2(gl_TexCoord[0]).st;
            //vec2 is the view vector.
            
        vec4 origcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
            //getting an original image tex
        vec4 bright(vec2 coo)
        {
            vec4 color = texture2D(bgl_RenderedTexture, coo);
            
            color = max(color - THRESHOLD, 0.0);
            
            return color / (color + OFFSET);
        
        }
        
        
        void main(void)
        {
            float value = 0.0150;      //value = distance away to check for pixel color (essentially scale of glare)

            vec4 flare = vec4( 0, 0, 0, 0 );
        flare += (2.0 * texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x - (value * 1.5), gl_TexCoord[0].st.y)));    //-1.5X translation

// flare += (2.0 * texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x + (value * 1.5), gl_TexCoord[0].st.y))); //1.5X translation

// flare += (1.0 * texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x - (value * 0.75), gl_TexCoord[0].st.y))); //-.5X translation
// flare += (1.0 * texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x + (value * 0.75), gl_TexCoord[0].st.y))); //.5X translation

// flare += texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x, gl_TexCoord[0].st.y + (value * 0.5))); //.5Y translation
// flare += texture2D(bgl_RenderedTexture, vec2(gl_TexCoord[0].st.x, gl_TexCoord[0].st.y - (value * 0.5))); //-.5Y translation

        flare /= 4.0;         // Average out the final color by number of samples
        flare = (flare * 1.00);
        
        gl_FragColor = origcolor + (flare * 1.00);
        
        }

“”"

if not ‘init3’ in obj:
cont.activate(filter)
obj[‘init3’] = 1



It should look like this… The think kinda removed the tabs and split some of the lines…

Wrong Approach: The Script shall only consist of the Part in the »ShaderText« (everything inbetween “”" to “”"). Then in the Logic Bricks you connect that to the Actuator »2D-Filter > Custom Filter«.

Huh. I was told once that doing it this way would improve performance, but I’m beginning to doubt that. Thanks, I’m using your script style, and it works much better. However, this doesn’t solve my lighting threshold problem… Might thee have such a solution? Thanks again!

Might thee have such a solution?
thee? were in 2012 now mate

Fair enough. I’ve watched too much Monty Python.

Moved from “Works in Progress and Game Demos” to " Game Engine Support and Discussion"

Also, when pasting code in these forums, it’s a good idea to use the

 BBcode tag.