Specific Objects/Materials shown when seen through another Shader/Material/Object

Hello, I had a question in regards to a unique shader which I haven’t seen done yet. I was wondering if it was possible to create a material that shows an object that is in other ways invisible in general.

Would I have to create a new default shader material in order to make objects invisible but shown through another material? I don’t know where to start as I’m a bit new to Shaders in general, both opengl and directx.

Much help is greatly appreciated.

At first, for what do you need to do such a thing? Perhaps there is a better way… Everything that comes to my mind consists of setting up two separate cameras, one rendering everything and the second one rendering everything except the objects that can be invisible… and then combine the two resulting textures with a mask rendered from the “window” objects.

EDIT: Alright this should be easier: First render the mask and set it up as a global screen space texture before the actual rendering. Then, in all the potentially invisible objects, you would sample this mask and use it to clip() the pixel or even multiply the alpha with this value for a smoother transition (but you would have to generate the mask in a smarter way then).