Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.97k stars 412 forks source link

An question about using msdfgen #89

Closed iomeone closed 4 years ago

iomeone commented 4 years ago

Hi, sorry to borther you again!

For example , original svg is <svg width="85" height="74" > <path d="M23.26998815917969,9.999998535156237c3.168,0 6.217,1.614 6.217,5.141c0,4.244 -3.347,7.173 -6.157,8.847c-2.152,1.315 -4.543,2.152 -7.053,2.152c-3.169,0 -6.277,-1.614 -6.277,-5.141c0,-4.244 3.407,-7.173 6.217,-8.847c2.152,-1.315 4.543,-2.152 7.053,-2.152Z" > </path> </svg> the command I used is : msdfgen.exe msdf -svg test.svg -o test.png -autoframe -size 85 74 -pxrange 37 -testrender testrender.png 85 74

the generated png is : 36

the render png is : 36Render

but the result I want to generate is : 109Render

I want the circle full fill the whole png, How can I tweak the args to make this happen?

The reason I want to do this is that: I just need to know the distance to the edge, so I can do some fancy effects with shader! but I want to leave the shape size unchanged.

Thank you very much!

Chlumsky commented 4 years ago

Well, according to -printmetrics, the bounding rectangle of the shape's coordinates is about 19.5 x 16.14 units, so if you want the SDF to be 85 x 74, then 85/19.5 = 4.359, so you need to add something like -scale 4.3.

As for your stated reason why you need this, I don't really understand, since if you're using a shader, you can literally make it any size you want from the SDF you already have.

iomeone commented 4 years ago

Yes, you are right that I can make it any size I want using a shader. I just have a 2d scene to layout lots of character, all character have different size and the arg of pxrange used to generate texture is different too.
originally all the msdf texture is generated with the -pxrange args of 2. But now I want to change the pxrange args to a different value(much more big). So the layout is completely changed. each character's bounding rectangle is shrank. For example, Originally the text coordinate is 2, 2 and width height is 20 , 20 Using newly generated Texture, the text's x y coordinate will be changed to 11 , 11 , And width height'll be changed to 10 ,10 (for example) I wonder if there is some quick way to fix this, or do I need to Recalculate the whole layout?

Chlumsky commented 4 years ago

So, first of all, if you're generating any kind of "layout", stop using autoframe, I don't know why I have to keep saying that to everyone. It wouldn't have happened then.

What you can do now is maybe increase the output image size by the same amount as you increased pxrange (or twice that?), or you can do -autoframe -printmetrics with the original settings and then pass the scale and translation it outputs with the new pxrange. Something like that.

In any case, I hope you're not making a character atlas by hand.

iomeone commented 4 years ago

Ok, I finally understand what's going on! Thank you for your time , I 'll try both method you suggested!

iomeone commented 4 years ago

I turns out your suggestion of ( increase the output image size by the same amount as you increased) works pretty well ! thank you!