How do I make a mirror that reflects objects but not the environment?

I have an interesting circumstance I’m trying to figure out how to address: I got a HDRI with a square mirror in the real image. I want to replicate its reflection. Obviously I add a plane and give it a fully reflective mirror material.

The problem is my plane also reflects the HDRI itself, duplicating the room already reflected in the original image in a way that looks worse. I want it to only reflect objects in the scene and treat the sky as transparent, while of course the normal camera still accounts for the background image. What’s the proper way of doing this, ideally without having to use multiple render layers?

A view of my setup, mirror plane deactivated… you can see the mirror in the room behind the bed.

Once the mirror plane is activated, the Suzanne head reflects as desired, but I also get an uglier reflection of the room itself… my goal is for the object to reflect but not the HDRI.

I believe you’ll need to use light groups for this, and the Light Path node doesn’t have an Environment Ray output

1 Like

From what little quick research I’ve been able to do (got to get to a lunch soon), I don’t think there is an easy way to do this with material nodes.

One possible, easy. but not perfect solution, would be to disable the glossy ray visibility of the background, and then just matte out the solid perfectly black pixels in the rest of the mirror. This might be really difficult in lower light scenes, but yours is so bright, that it should be pretty easy to get all the black pixels without affecting the reflected object.

Combined with a cryptomatte to just get the mirror, one could then run it through a color ramp to make a pretty nice alpha channel without having to manually rotoscope or anything.

Light groups might be a better solution? But I haven’t played with them at all, so don’t know their capabilities and currently don’t have time to research them for this comment.

2 Likes

Light groups came to mind, but initially seemed like overkill… might be the right option here.

I thought another way could be setting the background to transparent in the Render - Film settings. I’d need to remap the HDRI in the compositor of course: Don’t see a way to plug the world output in there… ironically you can’t even use an environment texture in the compositor just a standard image, thus you can’t remap it separately in there. For this reason even that is seemingly not an option.

And yes I played with the light path node thinking that would do it: Once more stuff aligns in such a way that none of the existing ray types can separate object reflections from the HDRI background.

You could insert a non reflective plane behind the camera that screens off all that you don’t want to reflect in the mirror. Make the material match the wall colour.

Then you keep the side reflections of the window up to the curtain, which look good and real, but effectively alter the back of the room.