Chlumsky / msdfgen

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

SVG with Quadradic path commands generates an SDF instead of MSDF #195

Closed rtrick closed 8 months ago

rtrick commented 8 months ago

First off, thank you for all the amazing work on this tool, it unlocks so much amazing art potential!

We believe we've found an unexpected behavior when processing some SVGs. Some of the SVGs we try to send through msdfgen appear to generate monochrome SDFs rather than MSDFs.

We believe we've isolated this to when an SVG has curve path commands. If the image only uses lines and arcs, we get an MSDF that renders as expected.

This is the unexpected result, generated from an SVG with curve commands SVG: HasQuadratic_ImportsAsSDF Output SDF: HasQuadratic_ImportsAsSDF Example render of the inner corner: Example_IncorrectlyRoundedInnerCorner

This is a the expected result generated from an SVG with only line and arc commands SVG: OnlyLinesArcs_ImportsAsMSDF Output MSDF: OnlyLinesArcs_ImportsAsMSDF Example render of the inner corner: Example_CorrectlyRoundedInnerCorner

rtrick commented 8 months ago

One of my teammates let me know that this is probably also important info for the report: We use a skia-enabled build of msdfgen, and we use skia for SVG parsing, not the default SVG parser.

Chlumsky commented 8 months ago

MSDF only takes care of sharp corners. Your SVG has rounded corners.

image

rtrick commented 8 months ago

Ah! I see. So even if at the rasterized resolution the edge looks "sharp" it needs to be a literal sharp corner to trigger the MSDF behavior.

This makes sense, as in our data, it seemed that the SVGs made in vector tools seemed to work reliably, but traced raster images more often had the issue.

Thanks so much for the clarity! We now know how to clean our data set. I think it would be reasonable to close this issue, though it would certainly be cool if there were some feature that could handle this automatically.

Thank you!