I'm trying to generate a 2D grid, for use in navigation, where each grid point holds the distance to the nearest obstacle (such as impassable terrain, or a constructed building). So for example, a grid point containing an obstacle would be 0, the grid point next to it would be 1, the next one further away would be 2, etc.
So far I've been able to accomplish this using multiple passes. Each pass, for every grid point, I take the lowest value from all neighbors, and add one. If I want to measure out to a max distance of, say, 10 grid points, I have to make 10 passes, slowly incrementing the most distance grid points.
My question is, is there a way to generate this sort of grid in just a single pass? This grid will be periodically updated during gameplay, and could be very large, so I don't want to be looping over it multiple times if I don't have to.