its actualy very simple just connect the foreground Alpha into the mask of the over node in the material of the transform compositing passes. that’s it