#version 330 /* E-ink reading mode shader for picom. Ported from snes19xx/surface-dots (Hyprland/hyprshade) to picom v12.5. Simulates e-ink display characteristics: - Warm cream paper tone with fiber grain texture - Soft charcoal ink with response curve matching real e-ink - Bayer matrix dithering to break up smooth gradients - Directional paper grain and subtle vignette */ in vec2 texcoord; uniform sampler2D tex; // 4x4 Bayer Matrix — breaks up smooth gradients into texture float getBayer(vec2 pos) { int x = int(mod(pos.x, 4.0)); int y = int(mod(pos.y, 4.0)); mat4 bayer = mat4( 0.0, 12.0, 3.0, 15.0, 8.0, 4.0, 11.0, 7.0, 2.0, 14.0, 1.0, 13.0, 10.0, 6.0, 9.0, 5.0 ); return bayer[x][y] / 16.0; } // Hash12 — fast deterministic noise, no trigonometry // (https://www.shadertoy.com/view/4djSRW) float hash(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); } // Multi-octave noise for realistic paper fiber texture float paperTexture(vec2 uv) { float n = 0.0; n += hash(uv * 0.3) * 0.6; // Very large fibers n += hash(uv * 0.8) * 0.4; // Large fibers n += hash(uv * 2.5) * 0.3; // Medium detail n += hash(uv * 6.0) * 0.2; // Fine grain n += hash(uv * 15.0) * 0.1; // Very fine grain return n / 1.6; } // Directional paper grain (fibers running in one direction) float directionalGrain(vec2 uv) { vec2 direction = vec2(0.7, 0.3); float grain = 0.0; grain += hash(uv * 3.0 + direction * 2.0) * 0.5; grain += hash(uv * 8.0 + direction * 5.0) * 0.3; return grain / 0.8; } // Subtle vignette for paper edge darkening float vignette(vec2 uv) { vec2 center = uv - 0.5; float dist = length(center); return 1.0 - smoothstep(0.4, 1.2, dist) * 0.15; } vec4 window_shader() { vec2 texsize = textureSize(tex, 0); vec2 normalizedCoord = texcoord / texsize; vec4 pixColor = texture2D(tex, normalizedCoord, 0); // BT.601 luma conversion — eyes see green brighter than blue float gray = dot(pixColor.rgb, vec3(0.299, 0.587, 0.114)); // E-ink characteristic response curve (ink clumping) gray = pow(gray, 1.2); // S-curve contrast — clips pure blacks/whites, keeps middle smooth gray = smoothstep(0.08, 0.92, gray); // Mid-tone boost float midBoost = smoothstep(0.3, 0.5, gray) * (1.0 - smoothstep(0.5, 0.7, gray)); gray += midBoost * 0.1; vec2 screenPos = gl_FragCoord.xy; // Paper grain float paperGrain = (paperTexture(screenPos * 0.3) - 0.5) * 0.035; float dirGrain = (directionalGrain(screenPos * 0.4) - 0.5) * 0.025; float bayerValue = getBayer(screenPos); // Apply texture to bright areas (paper) and slightly to mid-tones float textureMask = smoothstep(0.5, 0.95, gray); gray += paperGrain * textureMask; gray += dirGrain * textureMask * 0.7; // Dithering float ditherStrength = 0.025; gray += (bayerValue - 0.5) * ditherStrength * textureMask; // Vignette float vig = vignette(normalizedCoord); gray *= vig; gray = clamp(gray, 0.0, 1.0); // E-ink palette vec3 paperColor = vec3(0.94, 0.92, 0.86); vec3 inkColor = vec3(0.10, 0.10, 0.12); // Subtle color variation for paper texture float colorVariation = hash(screenPos * 0.08) * 0.02; paperColor += vec3(colorVariation, colorVariation * 0.5, -colorVariation * 0.2); vec3 finalColor = mix(inkColor, paperColor, gray); return vec4(finalColor, 1.0); }