aboutsummaryrefslogtreecommitdiff
path: root/.config/hypr/shaders/04_optics_compensate.glsl
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2026-01-11 19:18:06 +0530
committerkrolxon <krolyxon@tutanota.com>2026-01-11 19:18:06 +0530
commitea8f17368def0b581efcc332d057c0a034d4da9b (patch)
tree5fd0bfd6627d34b93090d79628bdd87793e9f715 /.config/hypr/shaders/04_optics_compensate.glsl
parent4c31a041975718cc2fb933012a303cf457475ce7 (diff)
add shader script and keybinds
Diffstat (limited to '.config/hypr/shaders/04_optics_compensate.glsl')
-rwxr-xr-x.config/hypr/shaders/04_optics_compensate.glsl72
1 files changed, 72 insertions, 0 deletions
diff --git a/.config/hypr/shaders/04_optics_compensate.glsl b/.config/hypr/shaders/04_optics_compensate.glsl
new file mode 100755
index 0000000..ea426c5
--- /dev/null
+++ b/.config/hypr/shaders/04_optics_compensate.glsl
@@ -0,0 +1,72 @@
+#version 300 es
+// Retro CRT Shader - FULLY OPTIMIZED
+// Fixes: Resolution-aware scanlines, proper vignette, edge clamping,
+// correct aberration direction, anti-aliased scanlines
+
+precision highp float;
+
+in vec2 v_texcoord;
+uniform sampler2D tex;
+out vec4 fragColor;
+
+// --- CONFIGURATION ---
+const float CURVATURE = 3.5;
+const float SCANLINE_STRENGTH = 0.25;
+// Approximate screen height in pixels (adjust to your resolution)
+const float SCREEN_HEIGHT = 1080.0;
+// Scanlines per screen height (lower = thicker lines)
+const float SCANLINE_COUNT = 540.0;
+const float ABERRATION = 0.002;
+const float VIGNETTE_RADIUS = 1.00;
+const float VIGNETTE_SOFTNESS = 0.45;
+// Phosphor glow simulation
+const float GLOW = 0.03;
+
+vec2 curveUV(vec2 uv) {
+ uv = uv * 2.0 - 1.0;
+ vec2 offset = abs(uv.yx) / vec2(CURVATURE);
+ uv = uv + uv * offset * offset;
+ uv = uv * 0.5 + 0.5;
+ return uv;
+}
+
+void main() {
+ vec2 uv = curveUV(v_texcoord);
+
+ // Black bezel for out-of-bounds
+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
+ fragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ return;
+ }
+
+ // FIXED: Clamp aberration samples to prevent edge artifacts
+ vec2 centerDist = uv - 0.5;
+ vec2 aberrOffset = centerDist * ABERRATION;
+
+ // FIXED: Correct direction - red focuses short, blue focuses long
+ float r = texture(tex, clamp(uv + aberrOffset, 0.0, 1.0)).r;
+ float g = texture(tex, uv).g;
+ float b = texture(tex, clamp(uv - aberrOffset, 0.0, 1.0)).b;
+ vec3 color = vec3(r, g, b);
+
+ // FIXED: Anti-aliased scanlines that don't shimmer during scroll
+ // Using smooth triangle wave instead of harsh sine
+ float scanlinePhase = uv.y * SCANLINE_COUNT * 2.0;
+ float scanline = abs(fract(scanlinePhase) - 0.5) * 2.0; // Triangle wave 0-1
+ scanline = smoothstep(0.0, 1.0, scanline); // Smooth it
+ float scanlineFactor = 1.0 - (SCANLINE_STRENGTH * (1.0 - scanline));
+ color *= scanlineFactor;
+
+ // Subtle phosphor glow (brightens slightly between scanlines)
+ color += GLOW * (1.0 - scanline);
+
+ // FIXED: Proper circular vignette with correct smoothstep bounds
+ float dist = length(centerDist) * 2.0; // 0 at center, ~1.414 at corners
+ float vignette = 1.0 - smoothstep(VIGNETTE_RADIUS, VIGNETTE_RADIUS + VIGNETTE_SOFTNESS, dist);
+ color *= vignette;
+
+ // Subtle brightness boost to compensate for darkening effects
+ color *= 1.1;
+
+ fragColor = vec4(clamp(color, 0.0, 1.0), 1.0);
+}