Skip to content

Instantly share code, notes, and snippets.

@kcbanner
Created April 6, 2014 16:44
Show Gist options
  • Save kcbanner/10008502 to your computer and use it in GitHub Desktop.
Save kcbanner/10008502 to your computer and use it in GitHub Desktop.
#version 150
#define BLUR_Y 0.004
uniform sampler2D diffuseTexture;
uniform sampler2D lightsTexture;
uniform float time;
uniform vec2 resolution;
uniform float distortion;
in vec2 texcoord_out;
out vec4 color0;
void main(void) {
vec2 pos = gl_FragCoord.xy / resolution;
float distance = 0.004 * (sin(200 * time) / 2 + 1);
distance *= sin(pos.y * 20 + 100 * time);
distance *= sin(pos.y * 300 + 10 * time);
distance *= 2 * sin(pos.y * 300 + time);
float c = 1;
c += 2. * sin(time * 4.0 + pos.y * 800.);
c += 1. * sin(time * 1.0 + pos.y * 800.);
c = mix(1, c, distortion);
distance *= distortion;
float blurAmount = BLUR_Y * distortion;
vec3 xCoords = vec3(texcoord_out.x - distance,
texcoord_out.x + distance / 4,
texcoord_out.x + distance);
float r = 0.0;
r += texture2D(diffuseTexture, vec2(xCoords.r, texcoord_out.y + blurAmount)).r * 0.2;
r += texture2D(diffuseTexture, vec2(xCoords.r, texcoord_out.y)).r * 0.6;
r += texture2D(diffuseTexture, vec2(xCoords.r, texcoord_out.y - blurAmount)).r * 0.2;
float g = 0.0;
g += texture2D(diffuseTexture, vec2(xCoords.g, texcoord_out.y + blurAmount)).g * 0.2;
vec4 center = texture2D(diffuseTexture, vec2(xCoords.g, texcoord_out.y));
g += center.g * 0.6;
g += texture2D(diffuseTexture, vec2(xCoords.g, texcoord_out.y - blurAmount)).g * 0.2;
float b = 0.0;
b += texture2D(diffuseTexture, vec2(xCoords.b, texcoord_out.y + blurAmount)).b * 0.2;
b += texture2D(diffuseTexture, vec2(xCoords.b, texcoord_out.y)).b * 0.6;
b += texture2D(diffuseTexture, vec2(xCoords.b, texcoord_out.y - blurAmount)).b * 0.2;
float lightR = 0.0;
lightR += texture2D(lightsTexture, vec2(xCoords.r + blurAmount, texcoord_out.y)).r * 0.2;
lightR += texture2D(lightsTexture, vec2(xCoords.r, texcoord_out.y)).r * 0.6;
lightR += texture2D(lightsTexture, vec2(xCoords.r - blurAmount, texcoord_out.y)).r * 0.2;
float lightG = 0.0;
lightG += texture2D(lightsTexture, vec2(xCoords.g + blurAmount, texcoord_out.y)).g * 0.2;
lightG += texture2D(lightsTexture, vec2(xCoords.g, texcoord_out.y)).g * 0.6;
lightG += texture2D(lightsTexture, vec2(xCoords.g - blurAmount, texcoord_out.y)).g * 0.2;
float lightB = 0.0;
lightB += texture2D(lightsTexture, vec2(xCoords.b + blurAmount, texcoord_out.y)).b * 0.2;
lightB += texture2D(lightsTexture, vec2(xCoords.b, texcoord_out.y)).b * 0.6;
lightB += texture2D(lightsTexture, vec2(xCoords.b - blurAmount, texcoord_out.y)).b * 0.2;
vec3 color = vec3(r, g, b) * vec3(lightR, lightG, lightB) * c;
color0 = vec4(color, center.a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment