How to make anything within object invisible (without boolean)?

Hey guys,
So I have an object, and I want to mask out a portion of it. How do I do that? I’m hoping it will also work with collections, and I also don’t want to use boolean.
I decided to make a small .blend file to demonstrate what im trying to do: project.blend
I want to mask out everything behind the portal, so I can see the red cube through it.
Any help would be appreciated!
Thanks!

There is a mask modifier.

https://docs.blender.org/manual/en/latest/modeling/modifiers/generate/mask.html

I would also like it work with collections, since thats what I’m primarily working with.

Sorry, I didn’t notice that… What do you mean? You want to mask elements of a collection, or mask parts of geometry that are in collection instances?

You can make a holdout for a particular object that you want to mask out for a render.
I recommend you watch this video if you are interested in something related to collections and view layers. Let me know if it helps!

i would like to mask out elements of a collection.

i dont think people understand what i’m trying to do, so i made a small blend file to demonstrate what im trying to do.
project.blend (964.8 KB)
i want to mask out everything behind the portal, so i can see the red cube through it.

Check this out, I saw this somewhere here (blenderartists). Move the cube towards the plane and through it.

collision-detection-mat.blend (798.0 KB)

EDIT: Is that what you want, to make a transparent circle in the box?

Make a collection and a view layer for each world and one for the portal, then compose them like this:

Here’s the blend file too:
portal-between-2-worlds-compositing.blend (875.4 KB)