updated chromatic aberration shader to general function

This commit is contained in:
Sven Vogel 2023-06-30 11:58:09 +00:00
parent 5c8966fbd7
commit 262c83223b
1 changed files with 29 additions and 23 deletions

View File

@ -2,23 +2,29 @@
const float Samples = 4.;
const float Strength = 0.085; // 2.5%
void mainImage( out vec4 fragColor, in vec2 fragCoord )
vec3 chromatic_aberration(in sampler2D tex, in vec2 uv)
{
vec2 uv = fragCoord/iResolution.xy-.5;
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(iChannel0, uv * fs.x+.5).r,
texture(iChannel0, uv * fs.y+.5).g,
texture(iChannel0, uv * fs.z+.5).b
texture(tex, uv * fs.x+.5).r,
texture(tex, uv * fs.y+.5).g,
texture(tex, uv * fs.z+.5).b
);
}
col /= Samples;
fragColor = vec4(col,1.0);
return col / Samples;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
fragColor = vec4(chromatic_aberration(iChannel0, uv),1.0);
}