Light Ghosting

uniform sampler2D bgl_RenderedTexture;
int samples = 8;
float gain = 0.5;
float spread = 0.03;
float  threshold = 1.0;
int volumes = 4;

void main(void) {
    vec3 screen = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st).rgb;
    vec2 deltacoord = (gl_TexCoord[0].st - vec2(0.5))*0.5;
    vec2 texcoord = -gl_TexCoord[0].st+1.0;
    float lum = 0.0;
    for (int i = 0; i < volumes; ++i) {      
        texcoord += deltacoord;
        for (int j = -samples; j < samples; ++j) {      
            vec2 newcoord = vec2(texcoord.x+(j*0.005), texcoord.y);
            float col = texture2D(bgl_RenderedTexture, newcoord).r;
            if (col >= threshold) {
                lum += spread/samples;
                } else {
                    lum += 0.0;
    float white = dot(screen, vec3(0.299, 0.587, 0.114)).r;
    float cval = ((0.5 - gl_TexCoord[0].x)*(0.5 - gl_TexCoord[0].x)) + ((0.5 - gl_TexCoord[0].y)*(0.5 - gl_TexCoord[0].y));
    float root = sqrt(cval);
    float stencil = max(lum , root/6);
    stencil = stencil-(root/6);
    gl_FragColor = vec4(screen+vec3(stencil*gain, stencil*gain, stencil*(gain*2)), 1.0);  


  1. Hmm this script does not work on Blender 2.64a :/

  2. It works for me... Could you send me a screenshot of what the console says when you try running the script? Knowing your pc's specs would be useful as well, I can try and get it running for you then.

  3. sorry for the late reply :( My pc specs are: Intel Core 2 Quad q8400, 4gb ddr2 and 9800GT
    Here is a screen shot

  4. sorry, here is a better image:

    1. Are you trying to run the code as a python script? or perhaps just from the text editor?, it needs to be run through a 2D filter actuator. I can't think why the first line would return an error otherwise.

    2. yes, that is what im doing, but it still doesnt work :/

  5. Could you try checking the script in an empty .blend, if it's only happening in the 1 file then it's a problem with the file, otherwise all I can suggest is updating your graphics drivers, because to be honest I have no clue why the first line is throwing out an error for you.

  6. :D i got it working!!! thanks man!

  7. can upload the script for motion blur?

    1. I had a link from when someone asked before!!

  8. Hi. Could you include a finished .blend of the 2d filters together? They don't work for me, and I would like to check to see if I'm just doing it wrong.