Loops in shader


#1

Hi !m trying to fix this shader. the effects is a radial blur around a point position, passing from the cpu in a array. The calculations works fine for each point and generates de effect, but as you can see in this picture, for each loop the shader keep generate samples, and i dont know how to avoid. i only want the blur for each point in the array

#version 150

in vec2 varyingtexcoord;
uniform sampler2DRect tex0;

uniform int size;


 float exposure = 0.79;
 float decay = 0.9;
 float density = .9;
 float weight = .1;
 int samples = 25;


out vec4 fragColor;
const int MAX_SAMPLES = 25;
const int N = 3;
uniform vec2 ligthPos [N];


int a = 1;


vec4 halo(vec2 pos){


    float illuminationDecay = 1.2;
    vec2 texCoord = varyingtexcoord;
    vec2 current = pos.xy;
    vec2  deltaTextCoord = texCoord - current;

    deltaTextCoord *= 1.0 / float(samples) * density;
    vec4 color = texture(tex0, texCoord);


    for(int i=0; i < MAX_SAMPLES; i++){

        texCoord -= deltaTextCoord;

        vec4 sample = texture(tex0, texCoord);
        sample *= illuminationDecay * weight;
        color += sample;
        illuminationDecay *= decay;

    }
    return color;

}


void main(){



        vec4 accum = vec4(0.0);

        for(int e = 0; e < N;e++){

            vec2 current =ligthPos[e];
            accum += halo(current);

        }

        fragColor = (accum) * exposure;


}

this is what happens:

and this is what i want:


#2

Hi! Could you share the Processing code?


#3

im not actually doing this in processing, because i need to send the positions in screen space and i found a function in openframeworks that do that work.
but its super simple, something like that:

bufferA.begin();
drawGeometry();
bufferA.end();

bufferB.begin();
shader();
bufferA.draw();
bufferB.end();

#4

i can see what is the problem of the shader, but i dont know how to fix it. For each loop its calculate the positions of the points, plus the others positions, since the fragment affect the all screen. i need some way to avoid that,and only calculate the necesarry points, and discard the others.