Solar panels work best in direct sunlight, but can also work without it.
Solar panels produce electricity using a combination of direct and indirect sunlight as inputs. Both forms of sunlight carry photons, which is what the solar panels convert into electric current.
If there is no direct sunlight available, solar panels will produce electricity using indirect sunlight alone.
There will, however, be a drop in performance in the absence of direct sunlight. That’s because solar panels need 1000 W/m2 of sunlight to reach their peak output; that much sunlight can only be achieved when there is direct sunlight shining.