forked from lettier/3d-game-shaders-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixelize.frag
More file actions
35 lines (25 loc) · 664 Bytes
/
pixelize.frag
File metadata and controls
35 lines (25 loc) · 664 Bytes
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
29
30
31
32
33
34
35
/*
(C) 2019 David Lettier
lettier.com
*/
#version 140
uniform sampler2D pixelizeTexture;
uniform vec2 enabled;
out vec4 fragColor;
void main() {
// Must be odd.
int pixelSize = 5;
vec2 texSize = textureSize(pixelizeTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;
float x = int(gl_FragCoord.x) % pixelSize;
float y = int(gl_FragCoord.y) % pixelSize;
x = floor(pixelSize / 2.0) - x;
y = floor(pixelSize / 2.0) - y;
x = gl_FragCoord.x + x;
y = gl_FragCoord.y + y;
if (enabled.x == 1) {
fragColor = texture(pixelizeTexture, vec2(x, y) / texSize);
} else {
fragColor = texture(pixelizeTexture, texCoord);
}
}