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);
pixel, pixelate, pixelize, square

More from Exuin

Screentone – Black spaced pixels

Box Blur

Moving Rainbow Gradient

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.
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
20 days ago

oh! bro you safe my game !