Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.92k stars 408 forks source link

"Fatter" fonts #69

Closed KakCAT closed 6 years ago

KakCAT commented 6 years ago

I'd love to use MSDF fonts (btw, kudos and thanks for the program/library) but font outlining is a must for the project I'd be using them.

Unfortunately the shaders I've seen with SDF outlines are very weak: artifacts and swiggly lines, specially when having to use pronunciated outlines.

So my idea is using two MSDF fonts instead of one: one for the outline (a "fatter" version of the font) and the usual font. Print first the outline and then the normal font (or maybe using two textures in the shader and do it in one pass)

And here comes the question: Is it possible/easy to create a fatter version of the font with msdfgen without the obvious loss of quality the MSDF outline shaders present? Could somebody give some pointers on what should be modified in the code to obtain that?

Thanks!

Chlumsky commented 6 years ago

Could you provide an example of the problem? Maybe you have the wrong shaders.

In any case, you cannot generate SDF for a "fatter" version of the font with this software, you'd have to use something else to modify the geometry.

Rhumage commented 6 years ago

It's probably the same issue as I had in #67.

What is the best way to calculate distance field in shaders? This is how I do it at the moment:

    uvec2 sz = PXRANGE / textureSize(msdfa, 0).xy;
    float dx = dFdx(texCoords.x) * sz.x;
    float dy = dFdy(texCoords.y) * sz.y;
    float toPixels = 8 * inversesqrt(dx * dx + dy * dy);
    return clamp(dist * toPixels + 0.5f, 0.0f, 1.0f);
KakCAT commented 6 years ago

Hi,

sorry for the delay. I thought it wasn't the same problem as #67 (that's why I opened a new issue) but actually it was the same indeed. Increasing pxrange and a little bit the texture resolution fixed the problem

I was using the shadron example for MSDF + border + shadows.

thanks to both.

Rhumage commented 6 years ago

Can you tell me what texture resolution and px range you're using?

And can you link me to the code for the example you mention?

KakCAT commented 6 years ago

Can you tell me what texture resolution and px range you're using?

And can you link me to the code for the example you mention?

sure. I moved from 32x32 to 48x48 and used pxrange 6. Font is arial.ttf (I used for a test) but I suppose that size, pxrange depends on font and amount of border.

shader:

https://gist.github.com/Chlumsky/263c960ae0a7df59afc2da4051eb0553

Rhumage commented 6 years ago

Thank you so much!