GLSL shader example

Radial Chromatic Aberration

Sample red and blue in opposite radial directions while green stays fixed; displacement vanishes near the center.

Live example

Edit the code and the preview updates as you type.

What to observe

Radial Chromatic Aberration.

Mechanism

Sample red and blue in opposite radial directions while green stays fixed; displacement vanishes near the center.

The controlling code

vec2 d=(uv-.5)*(.01+.07*u_parameter);c=vec3(texture2D(u_texture,uv+d).r,texture2D(u_texture,uv).g,texture2D(u_texture,uv-d).b);

Experiment

Set the multiplier .01+.07*u_parameter to .08, then to 0.. The red and blue copies separate near the image perimeter in the first case and align exactly with green in the second.

Debugging and cost

There are three texture reads, one for each output channel, and (uv-.5) keeps displacement zero at the center. Replace that vector with vec2(1.,0.) to make a uniform horizontal split and see why the radial version preserves the center.

Built-in functions used

Learn it step by step