Not render parts of texture that intersect each other

I’m trying to create a fog of war effect as detailed here: http://answers.unity3d.com/questions/620535/fog-of-war-depth-mask-technique.html

Essentially my problem boils down to transparent textures overlapping, whereas I’d like to not render any portions where they intersect. Could a shader do something like this? It might be a solution to my problem if that’s possible.

You might be able to do it if you set the render queue/type to opaque instead of transparent and make sure to write and test for depth-buffer values?

Seems like a good suggestion. I won’t test it though as I already tried another suggestion to generate the texture using SetPixels which is working well. I’m not sure which is the better performing solution on mobile but I may test both later on.

So GetPixels and SetPixels is incredibly slow for full-screen textures, so I’m returning to a shader approach…

I tried turning on ZWriting and played with ZTesting, and managed to get a little bit closer to removing the border by using ZTest Less…

…but can’t seem to fully eliminate the border. Can anyone nudge me in the right direction? I’m still a noob when it comes to depth testing.

I think what I need to do is somehow get the shader to put the pixel with the lowest alpha value into the depth buffer and ignore anything else. E.g.:

if ( newPixel.alpha < currentPixelInDepthBuffer.alpha )
currentPixelInDepthBuffer = newPixel;

I don’t know where to start with this. Would this be a blending type, a blend operation, require depth testing, or is it even possible at all?