Rendering only outside the fog

I am trying to implement a simple 2d fog of war; main idea is to keep a black but somewhat transparent rectangle sprite in front of camera but circularly reveal around units. (I am thinking of finding the point by ray-casting but a better idea is very welcome)

Naturally when an enemy shows up, you will see them outside the fog. I knew it could be done by disabling/enabling render component by some visibility check, though what I am curious about is whether we can do this through shading: some kind of fragment check maybe. This way exactly what part of the incoming object is visible would be seen outside the fog. If it was half visible then the other side would still look as grayed out background.

I used Zbuffers to achieve exactly what I desire, hope this doesn’t create some zfighting problems on different platforms. Each unit has a circular texture to create an aperture through fog, so no need for checking locations.