#version 130

uniform vec2 screenSize;

flat in vec2 p0;
flat in vec2 p1;
flat in vec4 values;

vec2 dp;

float computeSample(in vec2 pos)
{
    float y=abs(dot(vec2(dp.y,-dp.x),p0-pos));
    float a=dot(dp,p0-pos);
    float b=dot(dp,p1-pos);
    return (y/(atan(b/y)-atan(a/y)));
}

void main()
{
    vec2 screenPos=gl_FragCoord.xy;
    dp=normalize(p1-p0);
    float integral=computeSample(screenPos+vec2(0.1294,0.4829));
    integral+=computeSample(screenPos+vec2(0.3535,-0.3535));
    integral+=computeSample(screenPos+vec2(-0.4829,-0.1294));
    integral=3/integral;
    gl_FragColor=integral*values/256;
}