Pixel Text Shader
This shader is essentially anti-anti-aliasing and is crazy stupid simple.
It will calculate a threshold value of pixels composing the text it is applied to and then force anything above the threshold to be fully opaque and anything below to be fully transparent. This is a nice effect to have if you are attempting a style that doesn’t use any anti-aliasing or texture filtering.
Godot 3 used to have a built-in solution for this but since it appears to be absent from Godot 4, I decided to make this shader so I can have crispy text without any anti-aliasing blurriness at low resolutions.
Note: You can adjust the cutoff threshold in the editor to change how the text looks. Some fonts might look better at different thresholds.
Shader code
shader_type canvas_item;
uniform float threshold : hint_range(0.0, 1.0) = 0.5;
void fragment() {
COLOR.a = step(threshold, COLOR.a);
}
Ok so it turns out that this is totally unnecessary as you can just disable AA and/or font hinting in the font import settings in godot 4.
However, I will leave this shader up since you can still use it to do some interesting things like making the text look partially dissolved or whatever.