aboutsummaryrefslogtreecommitdiff
path: root/.config/hypr/shaders/09_pixelated.glsl
blob: 74251357c97b9b1c87db07f9e224d5242e83d17c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#version 300 es
// Pixelation Shader - OPTIMIZED
// Fixes: Sample from pixel CENTER (not corner), aspect ratio support

precision highp float;

in vec2 v_texcoord;
uniform sampler2D tex;
out vec4 fragColor;

// --- CONFIGURATION ---
// Pixels across the shorter dimension (height usually)
const float PIXEL_COUNT = 350.0;
// Set to your aspect ratio, or 1.0 for square pixels
const float ASPECT_RATIO = 16.0 / 9.0;

void main() {
    // Calculate pixel dimensions accounting for aspect ratio
    vec2 pixelCount = vec2(PIXEL_COUNT * ASPECT_RATIO, PIXEL_COUNT);
    vec2 pixelSize = 1.0 / pixelCount;
    
    // FIXED: Sample from pixel CENTER, not corner
    // This prevents the "swimming" artifact when content moves
    vec2 pixelCoord = floor(v_texcoord * pixelCount) + 0.5;
    vec2 sampleCoord = pixelCoord / pixelCount;
    
    fragColor = texture(tex, sampleCoord);
}