From 262c83223bde01c913c418b76d7dcf4b9fb774b1 Mon Sep 17 00:00:00 2001 From: Sven Vogel Date: Fri, 30 Jun 2023 11:58:09 +0000 Subject: [PATCH] updated chromatic aberration shader to general function --- .../Chromatic-Aberration/Image.glsl | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/Image-Filtering/Chromatic-Aberration/Image.glsl b/Image-Filtering/Chromatic-Aberration/Image.glsl index 9329c2b..6b5d1fa 100644 --- a/Image-Filtering/Chromatic-Aberration/Image.glsl +++ b/Image-Filtering/Chromatic-Aberration/Image.glsl @@ -1,24 +1,30 @@ - -const float Samples = 4.; -const float Strength = 0.085; // 2.5% - -void mainImage( out vec4 fragColor, in vec2 fragCoord ) -{ - vec2 uv = fragCoord/iResolution.xy-.5; - vec3 col = vec3(0); - - 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 - ); - } - col /= Samples; - - fragColor = vec4(col,1.0); + +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); } \ No newline at end of file