Quick idea for improving text antialiasing
See original GitHub issueI’m not sure if you’ve updated the antialiasing code recently, as I’m using an older version, but after finding a nice way to do antialiasing of shader-drawn circles, I wanted to try it out on your text as well, because the text is SDF-based, and the circle’s antialiasing is distance-based as well.
In my current version of Troika, you do return length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;
for the aa distance. This has the artifact that when viewing at an angle, the leftmost and rightmost edges get a somewhat visible blur:
I changed it to a scalar; the distance, just like in my circle code: return fwidth(distance) * 0.5;
With the distance passed in from troikaGetFragDistValue
like this: float distance = troikaGetFragDistValue(); float aaDist = troikaGetAADist(distance);
Doing it this way I don’t get the blurring artifact:
The 0.5
factor can be increased for a smoother antialiasing. E.g. 0.8
:
I thought maybe you were unaware of this method just like me, so thought I’d share it. My “implementation” does have some strange artifacts though (see below), and maybe this is why you opted for the other method. Also, I’m not exactly sure how you use the aaDist variable in the shader code, so you might be better equipped at implementing this. Maybe there’s some code that should be changed or removed because of this change for example, that could improve my “implementation” further.
I found this method of doing it in bgolus’s post here: https://forum.unity.com/threads/antialiasing-circle-shader.432119/ where there’s some more info. He also says that you can do for example length(vec2(dFdx(distance), dFdy(distance)))
instead of fwidth(distance)
for even greater precision, although I’m not sure if this is negligible or not.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
Top GitHub Comments
Thanks @canadaduane, I can definitely see the improvement in the stretched parts. I can also see the ugly artifacts popping up there between the L’s in HELLO, which we’d definitely need to figure out before adopting this change.
Anecdotally: I’ve also found that tweaking the constant to 0.25 (from 0.5) makes a nice crisp edge as well: