Shadertoy-Shaders/Image-Filtering/Chromatic-Aberration/Image.glsl

30 lines
689 B
GLSL

const float Samples = 4.;
const float Strength = 0.085; // 2.5%
vec3 chromatic_aberration(in sampler2D tex, in vec2 uv)
{
vec3 col = vec3(0);
uv -= .5;
vec3 f = 1. - length(uv) * Strength*vec3(2.,1.,0.);
for (float i = 0.; i < Samples; i++)
{
vec3 fs = mix(f, vec3(1), i/Samples);
col += vec3(
texture(tex, uv * fs.x+.5).r,
texture(tex, uv * fs.y+.5).g,
texture(tex, uv * fs.z+.5).b
);
}
return col / Samples;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
fragColor = vec4(chromatic_aberration(iChannel0, uv),1.0);
}