Chlumsky / msdfgen

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

Msdf generation fails on symbol with several nested holes #170

Closed Dollab closed 1 year ago

Dollab commented 1 year ago

Hi, first of all thanks a lot for this amazing library.

I've encountered a specific shape that seems to produce an error in the output msdf. You can see below the svg file describing the shape, the resulting msdf and an example of a render using the msdf.

The upper left hand rectangle should be hollowed but it's marked as "filled".

The results can be reproduced with the following code :


#include "msdfgen.h"
#include "msdfgen-ext.h"
#include <iostream>

using namespace msdfgen;

int main()
{
    std::cout << "Converting svg..." << "\n";
    Shape shape;

    if (loadSvgShape(shape, "./assets/floor.svg", 0)) {
        shape.normalize();
        //                      max. angle
        edgeColoringSimple(shape, 2.0);
        //           image width, height
        Bitmap<float, 3> msdf(3*24, 3*24);
        //                     range, scale, translation
        generateMSDF(msdf, shape, 2.0, 3.0, Vector2(0.0, 0.0));
        savePng(msdf, "./textures/output.png");
        simulate8bit(msdf);

        Bitmap<float, 1> test(256, 256);
        renderSDF(test, msdf, 1.0, 0.5);
        savePng(test, "./textures/test.png");
        std::cout << "Success!" << "\n";

    }

    return 0;
}

floor output test

Chlumsky commented 1 year ago

You either need to provide a correctly formed shape with consistent contour windings or use the Skia preprocessing.

Dollab commented 1 year ago

Thanks a lot for the superfast response. I'm not too versed in vcpkg, but I can't seem to find the skia feature ?

Chlumsky commented 1 year ago

Not sure what you mean, but the vcpkg feature is called geometry-preprocessing and it is enabled by default.

Dollab commented 1 year ago

Yes, my bad It works perfectly thanks !