Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fragment shader for glitch font
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
uniform float seed;
uniform float seed2;
uniform float seed3;
uniform float alphaBase;
uniform vec2 u_drawSize;
uniform float u_RGBDisplacementFactor;
uniform float u_XYDisplacementFactor;
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
float displacementX = 0;
float displacementY = 0;
if ((int(v_texCoord.y * 500.0) / (1 + int(step(0.5, seed) * 1))) % 2 == int(step(0.5, seed))) {
displacementX = u_XYDisplacementFactor * 1.0 / 200.0 * (seed * 2 - 1) * ((int(v_texCoord.y * u_drawSize.x * seed2) % 133) / 113.0f);
displacementY = u_XYDisplacementFactor * 1.0 / 200.0 * (seed2 * 2 - 1) * ((int(v_texCoord.y * u_drawSize.y * seed2) % 133) / 113.0f);
}
float displacementRX = seed2 * 0.01 * u_RGBDisplacementFactor;
float displacementGX = -seed3 * 0.006 * u_RGBDisplacementFactor;
float displacementBX = 0;//seed2 * 0.005;
float displacementRY = -seed3 * 0.005 * u_RGBDisplacementFactor;
float displacementGY = seed2 * 0.008 * u_RGBDisplacementFactor;
float displacementBY = 0;//seed3 * 0.006;
vec2 texCoordR = vec2(v_texCoord.x + displacementX + displacementRX, v_texCoord.y + displacementY + displacementRY);
vec2 texCoordG = vec2(v_texCoord.x + displacementX + displacementGX, v_texCoord.y + displacementY + displacementGY);
vec2 texCoordB = vec2(v_texCoord.x + displacementX + displacementBX, v_texCoord.y + displacementY + displacementBY);
float alphaR = texture2D(u_texture, texCoordR).a;
float alphaG = texture2D(u_texture, texCoordG).a;
float alphaB = texture2D(u_texture, texCoordB).a;
gl_FragColor = vec4(v_color.r * alphaR, v_color.g * alphaG, v_color.b * alphaB, (alphaR + alphaG + alphaB) * alphaBase);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment