Can I pixelate a 2D node (Sprite
in my case) in Godot? I need something like this:
It doesn't matter how to do it: with a shader or with code or with some tweaks. Any help appreciated.
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.