-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdither.gdshader
More file actions
37 lines (26 loc) · 769 Bytes
/
Copy pathdither.gdshader
File metadata and controls
37 lines (26 loc) · 769 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
36
37
shader_type canvas_item;
uniform int bits = 5;
uniform bool dithering = true;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
float dither4x4(vec2 position) {
int x = int(mod(position.x, 4.0));
int y = int(mod(position.y, 4.0));
int index = x + y * 4;
float[16] matrix = float[](
0.0, 8.0, 2.0, 10.0,
12.0, 4.0, 14.0, 6.0,
3.0, 11.0, 1.0, 9.0,
15.0, 7.0, 13.0, 5.0
);
return matrix[index] / 16.0;
}
void fragment() {
vec4 col = texture(SCREEN_TEXTURE, SCREEN_UV);
float levels = float(1 << bits);
if (dithering) {
float d = dither4x4(FRAGCOORD.xy);
col.rgb += d / levels;
}
col.rgb = floor(col.rgb * levels) / levels;
COLOR = col;
}