By Fermat's principle, a ray of light has to know where it will ultimately end up before it can choose the direction to begin moving in.
So either something is computing it or some exploration is happening at quantum level and we just see the final result.
> a ray of light has to know where it will ultimately end up before it can choose the direction to begin moving in
I'm no physicists, so I guess I'll ask it: Why?
Also related, why do some ray of light then "see" a black hole yet decide to head into them anyways, if they saw it before they went in that direction? Seems like a dumb move :)
Fermat's principle is an outcome of constructive interference of waves. It works both for classical and quantummechanical descriptions. E.g. check https://phys.libretexts.org/Bookshelves/University_Physics/U...