4 ms·
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
by adamjs 8y ago
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 8y agoOoh! 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-shader-peliminary.html http://blag.fingswotidun.com/2016/05/evolved-images-using-sh...
- adamjs 8y agoLooks neat! Glad to help.
- Jasper_ 8y agoI'm most curious how you're generating a sharp SDF in realtime. Are you just using the pseudo-SDF as recommended by Qin et. al?
- adamjs 8y agoBit hard to explain without examples but while traversing the beziers in shader, I test if we are equidistant to two or more beziers and do special handling to merge the two unclamped fields (normally we clamp 't' between [0, 1] when sampling bezier distance, but for merging two fields we can project it infinitely and then select closest).