From 2857b5a31c940a0d9ec6611b4957e3b8285c2b06 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Mon, 1 Apr 2019 13:08:28 +0200 Subject: [PATCH] Add chromatic abberation to post shader --- res/shaders/post.frag | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/res/shaders/post.frag b/res/shaders/post.frag index fe66b1e..57e2814 100644 --- a/res/shaders/post.frag +++ b/res/shaders/post.frag @@ -10,6 +10,10 @@ uniform uint windowHeight; uniform float time; +const float chomatic_abberation_r = 0.0; +const float chomatic_abberation_g = 0.025; +const float chomatic_abberation_b = 0.05; + void main() { vec2 dx = vec2(1,0) * 1.0/windowWidth; vec2 dy = vec2(0,1) * 1.0/windowHeight; @@ -23,7 +27,9 @@ void main() { for (int x = -radius; x <= radius; x++) for (int y = -radius; y <= radius; y++){ vec2 p = UV + x*dx + y*dy; - color += texture(framebuffer, p); + color.r += texture(framebuffer, (p-0.5)*(1+z*chomatic_abberation_r) + 0.5).r; + color.g += texture(framebuffer, (p-0.5)*(1+z*chomatic_abberation_g) + 0.5).g; + color.b += texture(framebuffer, (p-0.5)*(1+z*chomatic_abberation_b) + 0.5).b; } color /= pow(2*radius+1, 2); color_out = vec4(color * (1-pow(length((UV-0.5)*1.2), 3)), 1.0); // vignette