4 ms·
Author here. That's a neat trick! > I mention this because the mystery of the getDistance() function is often one of the tricky parts of demos like these. I a
by rjkaplan 6y ago
Author here. That's a neat trick!
> I mention this because the mystery of the getDistance() function is often one of the tricky parts of demos like these.
I agree! In the demos I use a library I wrote to generate 2D distance fields: https://github.com/ryankaplan/gpu-distance-field https://github.com/ryankaplan/gpu-distance-field
It's also pretty fast :)
- johndough 6y agoComputing distance fields with a jump flooding approach in O(n log n) is neat, but there is a O(n) algorithm, which might be faster https://prideout.net/blog/distance_fields/ https://prideout.net/blog/distance_fields/
- rjkaplan 6y agoNeat! In my experience jump flooding on the GPU is faster than any CPU side approach for images bigger than a few hundred pixels. It's O(n ^ 2 log n) which sounds really expensive, but it requires just O(log n) draw calls. The link you provided also describes a GPU amenable approach, but it says that jump flooding on the GPU is faster. > For a more efficient GPU-amenable method, see also jump flooding by Rong and Tan. Their method generates a closest point coordinate field from which a distance field can be derived.