SHADERS for absolute N00BS in Godot

Опубликовано: 17 Май 2026
на канале: CallousCoder
497
29

Today we will start you off with a 2D fragment #shader in #GODOT by writing very simple pixelate and chromatic aberration shader. If you can't follow this, you may need to go back to high school and learn more #maths

Code:

shader_type canvas_item;
uniform float pixel = 0.008;

vec4 pixelate(sampler2D t, vec2 uv, float p_fact){
uv += -1.*mod(uv, p_fact).xy;
vec4 color = texture(t, uv);
return color;
}

void fragment() {
vec2 uv = FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE);

vec4 color = pixelate(TEXTURE, uv, pixel);

//chormatic ab
float ab_r = texture(TEXTURE, vec2(uv.x-sin(TIME*2.)*0.05, uv.y)).r;
float ab_b = texture(TEXTURE, vec2(uv.x+sin(TIME*5.)*0.05, uv.y)).b;

//eliptical mask
vec2 trans = 2.0 * uv - 1.0;
float mask = smoothstep(1.0, 0.1, dot(trans, trans));

color.r = mix(ab_r, color.r, mask);
color.b = mix(ab_b, color.b, mask);
COLOR = color;
}