summaryrefslogtreecommitdiff
path: root/config/picom/shaders/pixelize_median.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'config/picom/shaders/pixelize_median.glsl')
-rwxr-xr-xconfig/picom/shaders/pixelize_median.glsl85
1 files changed, 85 insertions, 0 deletions
diff --git a/config/picom/shaders/pixelize_median.glsl b/config/picom/shaders/pixelize_median.glsl
new file mode 100755
index 0000000..9d695aa
--- /dev/null
+++ b/config/picom/shaders/pixelize_median.glsl
@@ -0,0 +1,85 @@
+#version 330
+
+#define vec vec3
+#define toVec(x) x.rgb
+
+#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);
+#define mn3(a, b, c) s2(a, b); s2(a, c);
+#define mx3(a, b, c) s2(b, c); s2(a, c);
+
+#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b); // 3 exchanges
+#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d); // 4 exchanges
+#define mnmx5(a, b, c, d, e) s2(a, b); s2(c, d); mn3(a, c, e); mx3(b, d, e); // 6 exchanges
+#define mnmx6(a, b, c, d, e, f) s2(a, d); s2(b, e); s2(c, f); mn3(a, b, c); mx3(d, e, f); // 7 exchanges
+
+
+in vec2 texcoord; // texture coordinate of the fragment
+
+uniform sampler2D tex; // texture of the window
+
+
+ivec2 window_size = textureSize(tex, 0); // Size of the window
+ivec2 window_center = ivec2(window_size.x/2, window_size.y/2);
+
+/*
+These shaders use a sorta hacky way to use the changing
+window opacity you might set on picom.conf animation rules
+to perform animations.
+
+Basically, when a window get's mapped, we make it's alpha
+go from 0 to 1, so, using the default_post_processing to get that alpha
+we can get a variable going from 0 (start of mapping animation)
+to 1 (end of mapping animation)
+
+You can also set up your alpha value to go from 1 to 0 in picom when
+a window is closed, effectively reversing the animations described here
+*/
+
+// Default window post-processing:
+// 1) invert color
+// 2) opacity / transparency
+// 3) max-brightness clamping
+// 4) rounded corners
+vec4 default_post_processing(vec4 c);
+
+// If you have semitransparent windows (like a terminal)
+// You can use the below function to add an opacity threshold where the
+// animation won't apply. For example, if you had your terminal
+// configured to have 0.8 opacity, you'd set the below variable to 0.8
+float max_opacity = 0.9;
+float opacity_threshold(float opacity)
+{
+ // if statement jic?
+ if (opacity >= max_opacity)
+ {
+ return 1.0;
+ }
+ else
+ {
+ return min(1, opacity/max_opacity);
+ }
+
+}
+
+vec4 anim(float time) {
+// block size shrinks from 40→1
+ float block = mix(40.0, 1.0, time);
+ vec2 uvb = floor(texcoord / block) * block + block/2;
+ vec4 c = texelFetch(tex, ivec2(uvb), 0);
+ return c;
+}
+
+// Default window shader:
+// 1) fetch the specified pixel
+// 2) apply default post-processing
+vec4 window_shader() {
+ vec4 c = texelFetch(tex, ivec2(texcoord), 0);
+ c = default_post_processing(c);
+ float opacity = opacity_threshold(c.w);
+ if (opacity != 1.0)
+ {
+ c = anim(opacity);
+ }
+ return default_post_processing(c);
+}
+