Distance Fields
April 22, 2024
Distance fields!
Set up a process for generating distance fields from line drawings. Each non-transparent pixel is assigned a color representing its position, with the red channel storing the x coord and the green channel storing the y coord. Then each of the transparent pixels is filled in with the color corresponding to the closest solid pixel.
This way you can quickly find the closest point on the drawing to any particle simply by sampling the distance field texture at the particle’s position.