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

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