question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quick idea for improving text antialiasing

See original GitHub issue

I’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: image

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: image

The 0.5 factor can be increased for a smoother antialiasing. E.g. 0.8: image

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.

image

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
lojjiccommented, Oct 10, 2021

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.

1reaction
canadaduanecommented, Oct 9, 2021

Anecdotally: I’ve also found that tweaking the constant to 0.25 (from 0.5) makes a nice crisp edge as well:

return length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.25;
Read more comments on GitHub >

github_iconTop Results From Across the Web

P: Improve font antialiasing - Adobe Support Community - 12250483
I support the idea of adding features that make it possible to render text as per ClearType. Comments that "it's becoming obsolete" seem...
Read more >
The Ails Of Typographic Anti-Aliasing - Smashing Magazine
It takes only a quick glance to realize that anti-aliasing is extremely important to making text legible. With few exceptions, anti-aliased ...
Read more >
How to fix font anti-aliasing in IntelliJ IDEA when using high ...
Open your font in FontForge · Select all glyphs via Ctrl+A and clear all hints (Hints -> Clear Hints) · Select glyphs again...
Read more >
Learn better anti-aliasing for your pixel art - 2D Will Never Die
Ready to blow a few neurons out of your head? Take everything you've done so far, the legible and illegible text with and...
Read more >
How to make text render perfectly | Creative Bloq
While antialiasing improves the quality of text rendering, it's possible to improve the result further using subpixel antialiasing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found