Ray Marching Soft Shadows in 2D
There’s a simple trick you can use if you want to generate the distance field for text or simple shapes in the browser. The way you do it is by repeatedly drawing the text with strokeText, varying the stroke width and the stroke color.<p>For example, you fill the background with 100% white, and then draw a 10px stroke at 90% gray, 9px at 80%, 8px at 70%, etc. This is, most importantly, an extremely <i>fast</i> way to generate a distance field for text from JavaScript in the browser.<p>I mention this because the mystery of the getDistance() function is often one of the tricky parts of demos like these.