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