How to masked out object behind translucent material

I having a gun optic like this.
Pic 1: Current state: Looking through the scope i can still see part of the gun, and part of the optic itself.
Pic 2: What i wanted to achieve
I am currently using masked material to mask out what behind the lens entirely (Pic 2) but this method is very clunky and the transition is very choppy.
Are there any method to masked out object but only when you look at it through a translucent material ?. Or are there any better method to make scoping look realistic.



To be honest, I am not an expert when it comes to guns in FPS, so there are perhaps other articles which have better solutions. Depending on how the asset is setup, you could hide the visible front component when aiming down sight, and make it visible once you zoom out again. You could alternatively keep the sight in place but move the gun back a bit to account for the barrel.

I’ve kinda tried the same thing for a weapon shader but instead of the material being masked, I used a translucent material and custom stencil to hide parts of the weapons. Additionally, the inside of my scope - the part that zooms in is using a scene-color node with a zoom effect to mimic zooming like in the newer Call of Duty games.

This is before I had my weapon scope with the materials but I did nothing with the gun materials.

vs the gun using a translucent shader that hides the weapon itself based on the custom stencil of the scope material.

The problem is whenever I add any color or complexity to any of my weapons, their insides become their outsides like so:


So it becomes really off for some reason, I’m just wondering how you masked it with a masked material rather than how I did it with a translucent material.

BTW a plus side of using Scene-Color is that you are able to add some cool effects like thermals by just adjusting the color and using a custom-stencil node to highlight enemies.