How to utilize material (or object) index behind a refractive material in cycle?
I don't think it's possible to utilize material (or object) index behind a refractive material as it is.

Blender is correctly showing the mask of the object that form the camera point of view truly has the material assigned. The squared piece is made of glass, the fact that is somehow showing what's behind doesn't change the material which is made of.

We can try to mask the "perception" of the material, but we'll have to use the rendered image itself, because only there the optic calculation occurs. Think about a deforming glass as the one show below:



The refraction, the dimming of the bounced light, the bending of the geometry, the fact that on the short side of the box you cannot see the torus... are all effects that strictly depends on the characteristic of the material (ior for example) and of the geometry.

What I'm trying to say is that you can't get the mask without actually render the image, beacause is in the simulation that all effects take place.

Maybe one day someone will implement a object id pass capable of taking optics into account, but for the moment I would switch all the lights off, add an emission shader to the interested object and use the rendered image as a mask.



It's certenly not an optimal solution as you'll probably have to set up a parallel blendfiles just for this task.