Created
August 8, 2026 04:04
-
-
Save pedrominicz/8f98faa4a345320af72e4889a15c7fe5 to your computer and use it in GitHub Desktop.
Picom grayscale shader using Oklab perceptual lightness.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 330 | |
| in vec2 texcoord; | |
| uniform sampler2D tex; | |
| vec4 default_post_processing(vec4 c); | |
| float srgb_to_linear(float c) { | |
| return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); | |
| } | |
| float linear_to_srgb(float c) { | |
| c = clamp(c, 0.0, 1.0); | |
| return c <= 0.0031308 ? 12.92 * c : 1.055 * pow(c, 1.0/2.4) - 0.055; | |
| } | |
| float oklab_lightness(vec3 srgb) { | |
| float r = srgb_to_linear(srgb.r); | |
| float g = srgb_to_linear(srgb.g); | |
| float b = srgb_to_linear(srgb.b); | |
| // Linear RGB -> LMS | |
| float l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b; | |
| float m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b; | |
| float s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b; | |
| //l = sign(l) * pow(abs(l), 1.0/3.0); | |
| //m = sign(m) * pow(abs(m), 1.0/3.0); | |
| //s = sign(s) * pow(abs(s), 1.0/3.0); | |
| l = pow(l, 1.0/3.0); | |
| m = pow(m, 1.0/3.0); | |
| s = pow(s, 1.0/3.0); | |
| // LMS -> OKLab (lightness component only) | |
| return 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s; | |
| } | |
| vec4 window_shader() { | |
| vec4 color = texture2D(tex, texcoord / textureSize(tex, 0), 0); | |
| float lightness = oklab_lightness(color.rgb); | |
| float gray = linear_to_srgb(lightness * lightness * lightness); | |
| color.rgb = vec3(gray); | |
| return default_post_processing(color); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # picom --config "$HOME/.config/picom/picom.conf" | |
| backend = "glx"; | |
| # TODO: Set your username. | |
| window-shader-fg = "/home/<username>/.config/picom/oklab_grayscale.glsl"; | |
| root-pixmap-shader = "/home/<username>/.config/picom/oklab_grayscale.glsl"; | |
| no-use-damage = true; | |
| #force-win-blend = true; | |
| shadow = false; | |
| fading = false; | |
| inactive-opacity = 1.0; | |
| active-opacity = 1.0; | |
| frame-opacity = 1.0; | |
| blur-method = "none"; | |
| corner-radius = 0; | |
| inactive-dim = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment