Godot - can I pixelate a node (Sprite)?

833 views Asked by At

Can I pixelate a 2D node (Sprite in my case) in Godot? I need something like this:

![enter image description here

It doesn't matter how to do it: with a shader or with code or with some tweaks. Any help appreciated.

1

There are 1 answers

0
Yanb On BEST ANSWER

I've figured it out by myself, it was pretty easy indeed. I just need a shader:

shader_type canvas_item;

uniform float size_x = 32.0; // blocks by x direction
uniform float size_y = 32.0; // blocks by y direction

void fragment() {
    COLOR = texture(TEXTURE, vec2(floor(UV.x * size_x) / (size_x - 1.0), floor(UV.y * size_y) / (size_y - 1.0)));
}

The inside of fragment function is scaling the UV up, rounds it down using floor and scales the result back down. The image above (in the question) is pixelated down to 32x32 size, and after using this shader the Sprite looks just like in the image example.

P.S. It doesn't work for GUI nodes, maybe I'll solve this problem.