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);
}
Live Preview
Tags
aliasing, pixel, pixel text, text
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.

More from Creatorbyte

Related shaders

guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
nee1218
nee1218
22 days ago
Reply to  Creatorbyte

This is still a neat trick as I need to modify some shader that can blur some text. Thanks for sharing!