Camera effects in CanvasLayer (+Cromatic Aberration)

This commit is contained in:
Mario Brandao
2023-12-13 22:48:27 +01:00
parent 0fc19ef815
commit 1668629916
16 changed files with 224 additions and 90 deletions

View File

@ -1,9 +1,14 @@
shader_type spatial;
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear;
uniform int pixel_size = 1;
uniform float alpha = 0.1;
// inspired by https://www.youtube.com/watch?v=77F4ZjmQ07U
void fragment() {
vec2 VIEWPORT_SIZE = 1.0 / SCREEN_PIXEL_SIZE;
// a variant of nearest neighbour fragment shader_type
float x = float(int(FRAGCOORD.x) % pixel_size);
float y = float(int(FRAGCOORD.y) % pixel_size);
@ -12,6 +17,5 @@ void fragment() {
y = FRAGCOORD.y + floor(float(pixel_size) / 2.0) - y;
// set albedo value on the current coordinate based on vec2(x,y) / viewport_size
ALBEDO = texture(SCREEN_TEXTURE, vec2(x, y) / VIEWPORT_SIZE).xyz;
ALPHA = alpha;
COLOR = vec4(texture(SCREEN_TEXTURE, vec2(x, y) / VIEWPORT_SIZE).xyz, alpha);
}