Box Blur

Have you ever wondered what a box blur implementation would look like in Godot? No? Too bad!

Shader code
shader_type canvas_item;

void fragment(){
	vec2 pixel = UV / TEXTURE_PIXEL_SIZE;
	int x_min = max(int(pixel.x-1.), 0);
	int x_max = min(int(pixel.x+2.), int(1./TEXTURE_PIXEL_SIZE.x));
	int y_min = max(int(pixel.y-1.), 0);
	int y_max = min(int(pixel.y+2.), int(1./TEXTURE_PIXEL_SIZE.y));
	vec4 total = vec4(0., 0., 0., 0.);
	for(int i = x_min; i < x_max; i++){
		for(int j = y_min; j < y_max; j++){
			total += texture(TEXTURE, vec2(float(i), float(j)) * TEXTURE_PIXEL_SIZE);
	total /= 9.;
	COLOR = total;
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Exuin

Square Pixelation


Screentone – Black spaced pixels

Related shaders

Configurable Box Blur

Artsy Circle blur type thingy

Gaussian Blur


Inline Feedbacks
View all comments