
This shader code should do the trick, and it's pretty apparent that anything more than 2-3 pixels of aberration in any of the colors, at the very edges of the screen, is distracting and noticeable. (of course that depends on the resolution, the lens' aberattion is obviously resolution independent, so the units would be better in relative terms, but anyway the same code that I can artificially induce aberattion closer to the edges can be used to remove it as a postprocessing step). Now, the only question is, how to enable that generally in the control panel of your videocard, if that's even possible. (I think it is, I haven't mucked around too much in my AMD driver settings to see if / where you can set your own shader to be used all the time)
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 resolution;
uniform float time;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
void main(void)
{
vec2 uv = gl_FragCoord.xy / resolution.xy;
float timeFactorR = 0.5 + 0.5*sin(0.6*time);
float timeFactorG = 0.5 + 0.5*sin(0.2*time);
float timeFactorB = 0.3 + 0.8*sin(0.8*time);
// maximum aberration in number of pixels at uv.x == 0 or 1 (left or right edge)
const float redAberration = 10.0;
const float greenAberration = 0.0;
const float blueAberration = -10.0;
float pctEffect = abs(uv.x - 0.5) * 2.0 / resolution.x;
vec3 aberration = vec3(redAberration * timeFactorR,
greenAberration * timeFactorG,
blueAberration * timeFactorB);
aberration *= pctEffect;
vec3 col;
col.r = texture2D(tex0,vec2(clamp(uv.x+aberration.x, 0.0, 1.0),-uv.y)).x;
col.g = texture2D(tex0,vec2(clamp(uv.x+aberration.y, 0.0, 1.0),-uv.y)).y;
col.b = texture2D(tex0,vec2(clamp(uv.x+aberration.z, 0.0, 1.0),-uv.y)).z;
gl_FragColor = vec4(col,1.0);
}
Just paste it into
shadertoy and try out different textures (first slot only), and values for red / green / blue aberration in the shader code, then hit the compile button. if you put the same aberration value for all three, it will just squeeze/stretch the image horizontally. Yeah, there should be some kind of clamping in there, but I'm very rusty on GLSL and quite tired after a long 12 hour day at work coding this neat after effects realtime animation plugin for unity
Edited by RLBURNSIDE - 2/20/13 at 10:43pm