Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Chinese character rendering issues #181

Closed RikiLee closed 1 year ago

RikiLee commented 1 year ago

I use msdfgen.exe to generate an MSDF texture of the Chinese character '中' in size 32 32, but when I render it to an image with size 1024 1024, some strokes are broken.

When I change the texture size to 64 * 64, the result is better, but there still are a few holes in the character.

Is this a bug or did I misuse something?

The font file which I use is simsun.ttc , and the Unicode of the character is 0x4e2d. And many other Chinese characters have this problem too.

Chlumsky commented 1 year ago

Post pictures.

RikiLee commented 1 year ago

render This image is rendered by a 32 32 size texture. render This image is rendered by a 64 64 size texture. The hole is very small in the middle of the image. But when I use OpenGL to render this, a few holes appeared. image

@Chlumsky

Chlumsky commented 1 year ago

The lines in the font are way too thin for low resolution distance fields. Every line should be at least 1 or 2 pixels thick in the distance field in order to be encoded properly.

RikiLee commented 1 year ago

When I use a 128 *128 size texture, this problem disappeared. Thank you. By the way, is there any way to solve this problem when using a low-resolution SDF texture?

Chlumsky commented 1 year ago

You would have to make sure that the opposite edges that are close together have different colors in the MSDF scheme, but since there are only 3 available colors and you also need to switch them at corners, it may not be possible to satisfy both constraints. It is likely possible to generalize MSDF to 5 or more colors (channels), which would require multiple texture lookups, but I haven't tried implementing this.