Chromatic Aberration Filter v1.1.

I am sure there are better chromatic aberration filters out there but i decided to make my own since i figured it would be fun and not take very long.

This filter can use as many different colours as you want for the cromatic aberration effect, the higher the spread (disperseAmount) the higher you should make the amount of colors (samples) to prevent banding, a number of three samples looks the same than just using separate colour chanels.

Examples:



uniform sampler2D bgl_RenderedTexture;
vec2 texCoord = gl_TexCoord[0].st;
float distortAmount = 0.075;
float disperseAmount = 0.05;
float zoomAmount = distortAmount + disperseAmount;
int samples = 16;
vec2 zoom = texCoord - vec2(0.5, 0.5);
vec3 color(float mat){
    vec3 col = vec3(0.0, 0.0, 0.0);
    float hue = mat - floor(mat);
    col.x = clamp(max(hue * 6 - 4, -hue * 6 + 2), 0.0, 1.0);
    col.y = clamp(min(hue * 6 - 0, -hue * 6 + 4), 0.0, 1.0);
    col.z = clamp(min(hue * 6 - 2, -hue * 6 + 6), 0.0, 1.0);
    return col;
}
void main(){
    float osx = cos(atan(texCoord.y - 0.5, texCoord.x - 0.5)) * (pow(texCoord.x - 0.5, 2.0) + pow(texCoord.y - 0.5, 2.0));
    float osy = sin(atan(texCoord.y - 0.5, texCoord.x - 0.5)) * (pow(texCoord.x - 0.5, 2.0) + pow(texCoord.y - 0.5, 2.0));
    vec2 offset = vec2(osx,osy);
    vec4 col = vec4(0.0,0.0,0.0,1.0);
    float i = 0;
    while(i < samples){
        col += texture2D(bgl_RenderedTexture,texCoord + offset * (distortAmount + disperseAmount * (i / samples)) - zoom * zoomAmount) * color(i / samples) / (samples / 2);
        i++;
    }
    gl_FragColor = col;
}

I hope this can be of use to someone.

NOTE: the filter Zooms the image to hide the parts of the image that have overflowing coordinates after distortion, to disable this change “float zoomAmount = distortAmount + disperseAmount;” to “float zoomAmount = 0.0;”

Please, let me know if you plan on using this on your project.