I'm trying to overlay some animated 3D models over live action footage. Some of the models (I'll call them collection A) will appear behind objects that are in the footage. I also have matching models for the live action objects that will be in front (collection B) and they are already animated to move exactly like the live action versions. I hope I'm explaining that clearly.
My issue is that I want to only be able to see the live action footage of collection B. I want the collection B 3D models to be transparent, but still occlude collection A so that collection A appears behind the footage of collection B.
I'm not sure that there's actually a way to do this, even with custom material nodes. I've seen posts describing a way to do it with compositing, but I wasn't able to replicate it. I would very much appreciate any help.
I'm on version 2.9, with the eevee engine.
Unfortunately, I can't upload my actual .blend file or screenshots, since this is for work. But as an example, in the screenshot below, I'd like the cube to be completely transparent, and the desert to show through. But I want the piece of the sphere that is covered by the cube to also be transparent, and the desert to show through that as well.
Here is my current compositing setup: