Getting pixel occlusion map

I’m experimenting with using UE4 for generation video frames together with accurate optical flow.

There’re serious problems with Velocity material out of the box, but after applying https://github.com/EpicGames/UnrealEngine/pull/6933 I now get absolutely correct motion vectors, textures warp perfectly from one frame to another.

The only remaining problem is occlusions. Obviously, if previously unseen point of object got projected to a frame, velocity vector of corresponding pixel is of no use and should be ignored. Thus, I need to generate a binary mask to detect such pixels.

Any ideas how to implement that?

[This is a cross-post of Getting pixel occlusion map, hope it’s ok]