4 ms·
Is there a library that can generate SDFs directly from the font's Bezier curves?
by jcarrano 3y ago
Is there a library that can generate SDFs directly from the font's Bezier curves?
- contravariant 3y agoDistance to a Bezier curve is an interesting one. For an n-degree Bezier it's easy to turn it into a problem to find a root for a 2n-1 degree polynomial, but that means anything for n>2 is going to be tricky to do in closed form. A few iterations of Newton's method with a good initial guess could go quite far though.
- mistercow 3y agoI did some experiments with shaders to stroke bezier curves many years ago, and iirc, the easiest (reasonably efficient) route I found if you have a cubic spline is to fit a quadratic spline to it first, then just transform and solve it as distance to a parabola.
- dahart 3y agoYes, tricky, a.k.a. impossible. ;) There is a neat closed-form solution for the n=2 quadratic Bezier floating around on ShaderToy, based on the trig solution of the cubic equation [1] and I’m fascinated by the link between cubics and circles [2] [1] https://en.wikipedia.org/wiki/Cubic_equation#Trigonometric_solution_for_three_real_roots https://en.wikipedia.org/wiki/Cubic_equation#Trigonometric_s... [2] https://en.wikipedia.org/wiki/Cubic_equation#Geometric_interpretation_of_the_roots https://en.wikipedia.org/wiki/Cubic_equation#Geometric_inter...
- gsliepen 3y agoThe FreeType library can generate SDFs from TrueType fonts. I am not sure whether it uses the Bezier curves directly though, or first renders to a bitmap.