Godot Version
Godot 4.3
Question
I’m making a pixelate shader for a project, but I’m running up against a problem that I think is due to anti-aliasing.
Here’s the code for the shader:
shader_type canvas_item;
uniform int resolution = 80;
void fragment() {
vec2 nearestCenterUV = (floor(UV*float(resolution))+vec2(0.5,0.5))/float(resolution);
COLOR = texture(TEXTURE, nearestCenterUV);
}
Essentially each pixel in the output is set to the colour of the input pixel that lands in its center.
I’m currently using a sprint2D to test this.
Here’s my current input which is an svg of a star with a grey background, and the output where the resolution is set to 80.
The code itself seems to be working fine, but my problem is the greyish pixels on the edge of the output’s star. My desired output is one where every pixel is either part of the white star or the grey background, with no in-between pixels. I assume the reason the in-between pixels appear is that before the image is run through the shader it gets anti-aliased, and some of the anti-aliased input pixels end up landing in the centers of the output pixels.
My question is (if I’m correct in my assumption) how do I stop the image from being anti-aliased and instead run the shader on the raw svg. (Also, if anybody notices a way to improve the shader code I would appreciate the advice since shaders are still quite new to me)