From 0c052ad410ac400b92533e4062d4f8c25cb2c458 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 1 Dec 2025 10:08:43 +0000 Subject: Add Glitch shade --- config/picom/shaders/glitch.glsl | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 config/picom/shaders/glitch.glsl (limited to 'config/picom/shaders/glitch.glsl') diff --git a/config/picom/shaders/glitch.glsl b/config/picom/shaders/glitch.glsl new file mode 100644 index 0000000..be28f78 --- /dev/null +++ b/config/picom/shaders/glitch.glsl @@ -0,0 +1,86 @@ +#version 330 + + +int delta = 20; +float barh = 0.02; +float barw = 0.4; +int nbar = 16; + +float maxoff = 5; +float minoff = 2; + +in vec2 texcoord; // texture coordinate of the fragment + +uniform sampler2D tex; // texture of the window +ivec2 window_size = textureSize(tex, 0); +ivec2 window_center = ivec2(window_size.x/2, window_size.y/2); + +// Default window post-processing: +// 1) invert color +// 2) opacity / transparency +// 3) max-brightness clamping +// 4) rounded corners +vec4 default_post_processing(vec4 c); + +uniform float time; // Time in miliseconds. + +float alpha = round(time/delta); // Like time, but in seconds and resets to + +// Pseudo-random function (from original shader) +float random(float n) { + return fract(sin(n) * 43758.5453f); +} + +float get_box() { + float n = random(alpha)*(nbar); + + for(int i=0;i y && texcoord.y < y + h + && texcoord.x > x && texcoord.x < x + w) { + return i*w*h*y*x*n; + } + } + return -1.0f; +} + +float rand_offset(float b) { + return (random(b*64) - 0.5) * (maxoff*2); +} + +vec4 window_shader() { + float b = get_box(); + + if (b == -1.0) { + vec4 c = texelFetch(tex, ivec2(texcoord), 0); + return default_post_processing(c); + } + //b = random(mod(alpha, 2000)); + + // Offsets in pixels for each color + vec2 uvr = vec2(rand_offset(b*1), rand_offset(b*6)); + vec2 uvg = vec2(rand_offset(b*2),rand_offset(b*7)); + vec2 uvb = vec2(rand_offset(b*3),rand_offset(b*8)); + + // Calculate offset coords + uvr += texcoord; + uvg += texcoord; + uvb += texcoord; + + // Fetch colors using offset coords + vec3 offset_color; + offset_color.x = texelFetch(tex, ivec2(uvr), 0).x; + offset_color.y = texelFetch(tex, ivec2(uvg), 0).y; + offset_color.z = texelFetch(tex, ivec2(uvb), 0).z; + + // Set the new color + vec4 c; + c.w = texelFetch(tex, ivec2(uvr), 0).w; + c.xyz = offset_color; + + return default_post_processing(c); +} + -- cgit v1.2.3