
Introducing the Distance Field Generator - jcelerier
http://blog.qt.io/blog/2018/10/10/introducing-distance-field-generator/
======
raphlinus
My personal feeling is that the world is moving on from distance fields, and
the state of the art is doing vector rasterization in the GPU. There are a few
approaches to these, and currently one of the most promising is pcwalton's
Pathfinder. Distance fields require lots of memory, have an expensive
preprocessing step (and doing that ahead of time, as in this work, limits
flexibility), and don't render very thin fonts well. GPU vector rasterization
doesn't suffer from any of these limitations, but does of course require more
sophisticated GPU programming.

~~~
Jasper_
Pathfinder 2 is now mostly a CPU approach with very little done on the GPU,
because you really want to avoid late-Z. I don't know of anybody else doing
state-of-the-art GPU vector rasterization. Slug has the same pitfalls as
Pathfinder 1 (late-Z & overdraw) and also requires an expensive preprocessing
step.

I don't think distance fields are the correct approach either, though the work
that Adam Simmons is doing to analytically solve beziers on the GPU is
interesting:
[https://twitter.com/adamjsimmons/status/730911372532322304](https://twitter.com/adamjsimmons/status/730911372532322304)

~~~
adamjs
I actually moved all of that to the CPU (parallel, SIMD) and am using it in
Ultralight [1] to generate high-precision SDFs for font-glyphs and small
paths. I'll release the GPU-based implementation when I have more time.

If you're interested in the details of the GPU-based implementation, I pre-
sort the path data into bins on CPU, encode it to a dynamic texture, traverse
the structure in shader using a modified BVH, and calculate the exact distance
to individual Beziers using root finding, which I open-sourced here [2]. It's
very fast and avoids overdraw through the use of a low-res stencil mask also
encoded into texture. There's of course a lot more nuance than that (fill
calculation, level-of-detail, etc.) but that's for a long blog post.

\- [1] [https://ultralig.ht](https://ultralig.ht)

\- [2]
[https://www.shadertoy.com/view/ltXSDB](https://www.shadertoy.com/view/ltXSDB)

~~~
Lerc
Ooh! thanks for the shadertoy link. I'd been struggling with how to do my
curved shapes for my evolver.

[http://blag.fingswotidun.com/2016/05/evolved-images-using-
sh...](http://blag.fingswotidun.com/2016/05/evolved-images-using-shader-
peliminary.html)

~~~
adamjs
Looks neat! Glad to help.

------
londons_explore
This post is about making a time-memory tradeoff by precomputing some
intermediate steps in font rendering.

Whenever considering a time-memory tradeoff, one needs to consider both time
and memory.

This post makes absolutely no mention of the additional memory use.

