The effect you are looking for is called chromatic aberration, which you can see on Wikipedia. You have already received a solution, but I consider it my duty to be a physicist to give you a deeper understanding of what is happening and how the effect can be generalized.
Remember that each camera has a certain aperture, and light is usually described as waves. The interaction of the waves with the aperture is called diffraction, but when this happens mathematically, it is just a convolution of the wave function with the Fourier transform of the aperture function. Diffraction depends on the wavelength, so this creates a spatial shift depending on the color. Another effect is dispersion, i.e. Dependence on the refraction of the wavelength. Again, diffraction can be described by convolution.
Now convolutions can be connected by a chain, which gives a complete convolution kernel. In the case of a Gaussian smearing filter, the convolution core is a Gaussian distribution that is identical across all channels. But you may have different convolution kernels for each target channel. That @bernie actually offers kernel convolution boxes shifted by a few pixels in each channel.
This is a good GLSL convolution filtering tutorial. You can use for loops, not for unrolling loops. http://www.ozone3d.net/tutorials/image_filtering_p2.php
I suggest you use some Gaussian kernels, and the blurriness for red and blue will be stronger than green and, of course, slightly offset central points.
source share