Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Japanese Font Rendering + Fix missing glyphs in msgothic_2 #13

Open
drojf opened this issue Dec 1, 2022 · 2 comments
Open

Improve Japanese Font Rendering + Fix missing glyphs in msgothic_2 #13

drojf opened this issue Dec 1, 2022 · 2 comments

Comments

@drojf
Copy link
Contributor

drojf commented Dec 1, 2022

To summarize, some Japanese characters are hard to read in our mod, which could be improved through various means. If w

If we're regenerating the fonts to fix this issue, we might as well also fix the missing glyph in Matsuribayashi (or just make msgothic2 the same set of characters as in msgothic0)

See

Below I've copied the previous discussion from discord:


OP:

I'm just being extremely picky, but I'm wondering if there's an easy way to change the japanese font. Any moderately complex kanji is always extremely aliased to the point where stroke lines blur together

image

I see there's a FontID setting in init.txt, but changing the parameter doesn't seem to do anything with the linux version
for comparison this is DejaVu Sans

image

and this is how the character 鷹 looks in umineko

image

drojf:

Unfortunately, it's kinda difficult....you need to get the font, put it into unity, generate a SDF font in unity, export the font from unity, then run our scripts (for ch1-8 only): https://07th-mod.com/wiki/developer/sharedassets/ui-editing-scripts/#adding-font-support-for-a-new-language-chapters-1-8-only
the fonts are converted to SDF style fonts, so it might just be a quality limitation due to how many characters we can fit in the texture atlas
from the wiki: >The current Japanese font contains about 3000 26pt Japanese characters and fits in 2048x2048, taking up 4MB.

I'm not sure what the max texture atlas size is in Unity, lemme double check since I was messing with this before...
oh ok, on the version of Unity used on Rei, the max texture atlas size is 8192 (for both dimensions), so we could technically have higher res fonts, but I haven't checked the older versions of unity
I'm not sure if there are any issues having such a large texture, though

OP (some time later):

some fonts look better than others at low res. I have a feeling msgothic is not well optimized. Noto Sans CJK JP is free and open source and might be a better choice. I'd try it myself but I apparently would need to install windows in order to use unity5

image

@drojf
Copy link
Contributor Author

drojf commented Dec 2, 2022

Some more discussion from discord

T — Today at 6:56 PM
This isn't a normal bitmap font. Not sure how those apply to SDF, if at all. That looks like font hinting, which 100% doesn't apply to SDF.
SDF just doesn't do close together lines very well
You're going to need a higher resolution

drojf — Today at 7:21 PM
was there a reason the res of the SDF texture was 2048 x 2048 and not bigger? Will it potentially cause problems on older computers if we make the texture too large?

I think I remember when I was playing around with making textures on Unity 5 for Rei, when I tried to make the glyphs too big (I think by default it's like 24 or 26 size, but making something like 50 screwed it up), it affected the font outline (it made it really thin). Then I tried to adjust the outline in the DLL, which kinda worked, but I forgot whether it was successful or not)

T — Today at 7:22 PM
Should be fine. Yes, the resolution does affect outline width, but we also have a configuration for that.
Only minus for making it bigger is file size. 2048x2048 is 4mb, 4096x4096 is 16
(Unity asset bundle stores these textures uncompressed)

drojf — Today at 7:23 PM
oh right now I rememebr, there was a command for it in the script file
ok, if I get around to it I'll try just increasing the SDF resolution/glyph size and see if it works

@drojf
Copy link
Contributor Author

drojf commented Feb 11, 2024

I probably will never get around to fixing this issue, but I thought I should record some more information:

The main things which need adjusting if you use a higher resolution than intended are:

  • The font size. This can be adjusted via the Mod****ModeSettingLoad() function in init.txt
    • This can also be edited in the GameObject for the font as fontscale or something
    • This can also be edited in the Unity Editor
  • The font outline. This can be adjusted via ModSetMainFontOutlineWidth(10);
    • This can also be edited in the material of the font by editing the "_OutlineWidth" parameter
    • This can also be edited in Unity by selecting a font asset, then under "Font Weights" changing "Normal Weight".
  • The font weight. I am in the process of adding a function to modify this.
    • This can also be edited in the Material for the font by editing the "_WeightNormal" parameter.
    • This can be changed from inside Unity by selecting a font asset, then under "Font Weights" changing "Normal Weight".

I'm also in the process of adding some in-game debug UI to change these 3 font parameters, and then display what commands you should paste into the init.txt file.

This makes it way easier to generate fonts because you then don't need to worry about having exactly the right font size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant