Square Pixelation

Since the other pixelation shaders I’ve seen have the “pixels” take on the aspect ratio of the image, here is a sqaure pixelation shader. Please don’t put pixel_size too high or Godot will crash, thanks.

Shader code
shader_type canvas_item;

uniform int pixel_size : hint_range(1, 100) = 1;

void fragment(){
	vec2 pos = UV / TEXTURE_PIXEL_SIZE;
	vec2 square = vec2(float(pixel_size), float(pixel_size));
	vec2 top_left = floor(pos / square) * square;
	vec4 total = vec4(0., 0., 0., 0.);
	for (int x = int(top_left.x); x < int(top_left.x) + pixel_size; x++){
		for (int y = int(top_left.y); y < int(top_left.y) + pixel_size; y++){
			total += texture(TEXTURE, vec2(float(x), float(y)) * TEXTURE_PIXEL_SIZE);
		}
	}
	COLOR = total / float(pixel_size * pixel_size);
}
Tags
pixel, pixelate, pixelize, square
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

Palette Swap (no recolor / recolor)

SPEEDLINES

Lines Screen Transition

Related shaders

3D Pixelation

256 colour pixelation

Animated 2D Fog(Optional Pixelation)

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
LURGX
LURGX
3 years ago

oh! bro you safe my game !

zMenta
zMenta
2 years ago

Awesome Shader!