Make object visible through selected objects only

I have an object, such as a gun, inside a cylindrical enclosure. The player can move around but since gun is inside cylinder, he can’t see it. Upon activating a power, he gets something like X-Ray vision and can see the gun through the cylinder. This much I have been able to achieve using another camera with higher Depth, Culling Mask set to only the gun’s layer and Clear Flags set to Depth Only.

Now I want that the object should be visible ONLY through the cylinder. Right now it shows on top of everything. If he has a wall or any other object in between him and the cylinder, the gun should not be visible. I cannot set the cylinder to transparent as the cylinder has its own texture and is opaque(wall and objects behind the cylinder shouldn’t be visible through it) and the gun should have 100% opaqueness and visibility(so no partial transparency).
I’m unable to find a way to do this. Don’t mind using shaders if it’s possible through them…

Probably you can raycast from the player (camera) to the gun and check if it hits a cylinder, using a tag for the cylinder. If it does then enable the renderer on the gun, else don’t.

This would look something like this:

Vector3 dir = gun.transform.position - camera.transform.position;
dir = dir.normalized;

if (Physics.Raycast(camera.transform.position, dir, out hit)) 
{
    if (hit.tag == "Cylinder")
    {
        gun.GetComponent<Renderer>().enabled = true;
    }
    else
    {
        gun.GetComponent<Renderer>().enabled = false;
    }
}

For more info check: