Particles or smoke rotating around an object or person in video - best way to composite?

Hello,
I’ve been wondering if there is a good way to achieve this effect. What I mean is when you have an object in a video footage and you want to make for example particles to be rotating around it.


The problem is that I cannot simply mask the object to the foreground since one part of the rotating particles has to be in front of the object and one behind it. What I did a few times was that I created a green object in the shape of the object in the video and put it in the middle of the particles and keyed it out in compositor (even better to make it black when using additive blending afterwards).

The problems are with animations when the object is moving but I guess one can use closed Bezier curves like a mask and animated that. Another drawback is that the greenscreen method might not work properly with transparent or multicolored stuff.

Isn’t there a way to render this helper object transparent but occluding the particles behind? Like being transparent in the output but not in the 3D world?

Thanks anyway and have a nice day! ^^

Z-depth should work.

Could you elaborate? Not sure how to use that for this effect.

Never mind! I got it! Thanks, using the depth is a great advice. I just connected the depth to a Math node with “Greater than” function and multiplied the mask (of the object from the video) with this result. Solved! Thanks!