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

Try different SDF granularities #38

Open
1 of 2 tasks
yhahn opened this issue Jun 2, 2014 · 10 comments
Open
1 of 2 tasks

Try different SDF granularities #38

yhahn opened this issue Jun 2, 2014 · 10 comments

Comments

@yhahn
Copy link
Member

yhahn commented Jun 2, 2014

We can get better compression ratios by reducing the granularity of the SDFs -- the following commit rounds each value to the nearest multiple of 8:

c213c12

Visually it's hard to see much difference once rendered and here is the space saving for a 0-255 range:

master 43124 bytes
compress-more 23208 bytes

This is a nice boost we can get now roughly for free since it doesn't affect the format/integrating projects -- later we may try other encodings for the bitmap (PNG, etc.) but those will be format-breaking.

Next actions

  • Try this and other settings (4 and 2? 16 is where I started to see artifacts...) with a variety of different fonts
  • This could be variable/env based so if you want a very high quality SDF you can set your settings that way
@mikemorris mikemorris self-assigned this Jun 18, 2014
@mikemorris
Copy link
Contributor

granularity bytes image
1 43124 1
2 36195 2
4 29376 4
8 23208 8
16 18583 16
32 14703 32

@mourner
Copy link
Member

mourner commented Jul 1, 2014

8 looks great to me

@mikemorris
Copy link
Contributor

This should likely be configurable by font. Simple serif and sans-serif fonts render quite cleanly with significantly reduced granularity, but curvy, swooping fonts like Mister K Pro Regular degrade in quality more quickly.

granularity bytes image
1 34290 1
2 28780 2
4 23552 4
8 18864 8

I may have the style mixed up a bit through, as I was trying to render Mister K at a larger size and even the rendering without reduced granularity appears much lower quality than @amyleew's. Is the screenshot below from a Mapnik rendering or GL? Could this particular font simply be ill-suited for SDF rendering?

@mikemorris
Copy link
Contributor

Mister K Onstage Pro Regular

Looks like 48px SDFs with granularity 4 is the sweet spot for this font, granularity 8 looks a bit lighter than full quality. The 24px SDFs (even at granularity 1) are woefully inadequate for this font.

sdf size granularity bytes image
48px 1 76339 1
48px 2 63117 2
48px 4 49998 4
48px 8 39182 8
24px 1 34290 24px

@amyleew
Copy link

amyleew commented Jul 1, 2014

@mikemorris Was testing the FF Font - Mister K. Screenshot directly from TM2.

@mikemorris
Copy link
Contributor

So 48px SDFs at granularity 4 look great for rendering curvy fonts like Mister K (even at large font sizes like 72px), but unecessarily bloat the SDFs for simpler fonts like Open Sans Regular at more typical font sizes.

Open Sans Regular

size granularity bytes
24px 8 23301
24px 1 43274
48px 4 63604

Maybe this calls for investigating 2-channel signed distance fields?

/cc @yhahn @kkaefer

@kkaefer
Copy link
Member

kkaefer commented Jul 3, 2014

Interesting results! We should definitely explore more here and make the font size configurable (currently it is hard coded to 24px). We could also explore not computing the SDF on the server, but on the client, and just send the antialiased glyph to the client. Similarly, another paper describes how to use the gradients in the distance field to compute sharper outlines and corners.

@mikemorris
Copy link
Contributor

You may find this interesting @rasagy, refs mapbox/mapbox-gl-js#3286

@mikemorris mikemorris removed their assignment Oct 19, 2016
@initialdmg
Copy link

I need to try a 48px CJK font, where to change the granularity param now? If distmap.c was moved into sdf-glyph-foundry? I just found the font scale ratio param , while i'm not sure if it is for the font size.

Btw, no need to modify mapbox-gl-js to use generated 48px glyphs, right?

@mikemorris
Copy link
Contributor

IIRC the font size you're looking for is hardcoded as 24 at

double size = 24 * scale_factor;

It looks like it's also passed in to sdf_glyph_foundry hardcoded separately a few lines below at

sdf_glyph_foundry::RenderSDF(glyph, 24, 3, 0.25, ft_face);

This should likely be made consistent to use the same variable instead of hardcoding values twice, and possibly made more modular, as the file size/clarity tradeoff can be different for more complex font styles.

Btw, no need to modify mapbox-gl-js to use generated 48px glyphs, right?

I don't remember, there may be some logic in there expecting glyphs of a certain size, or it could be reading those metrics from the protobufs. If this was made modular, would need to ensure the frontend rendering displayed glyphs as expected independent of node-fontnik render params.

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

Successfully merging a pull request may close this issue.

7 participants