2023-12-14 05:48:27 +08:00
|
|
|
shader_type canvas_item;
|
|
|
|
|
2023-12-14 04:47:08 +08:00
|
|
|
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
|
|
|
|
uniform int pixel_size = 1;
|
|
|
|
uniform float alpha = 0.1;
|
|
|
|
|
2023-12-16 06:58:06 +08:00
|
|
|
// based on https://www.youtube.com/watch?v=77F4ZjmQ07U
|
2023-12-14 05:48:27 +08:00
|
|
|
|
2023-12-14 04:47:08 +08:00
|
|
|
void fragment() {
|
2023-12-14 05:48:27 +08:00
|
|
|
vec2 VIEWPORT_SIZE = 1.0 / SCREEN_PIXEL_SIZE;
|
|
|
|
|
2023-12-14 04:47:08 +08:00
|
|
|
// a variant of nearest neighbour fragment shader_type
|
|
|
|
float x = float(int(FRAGCOORD.x) % pixel_size);
|
|
|
|
float y = float(int(FRAGCOORD.y) % pixel_size);
|
|
|
|
|
|
|
|
x = FRAGCOORD.x + floor(float(pixel_size) / 2.0) - x;
|
|
|
|
y = FRAGCOORD.y + floor(float(pixel_size) / 2.0) - y;
|
|
|
|
|
|
|
|
// set albedo value on the current coordinate based on vec2(x,y) / viewport_size
|
2023-12-14 05:48:27 +08:00
|
|
|
COLOR = vec4(texture(SCREEN_TEXTURE, vec2(x, y) / VIEWPORT_SIZE).xyz, alpha);
|
2023-12-14 04:47:08 +08:00
|
|
|
}
|