Render Layers with partly overlapping objects

I’d like to add some effects (blur/glow) to certain objects in the scene. Usually I would do this with render layers. The problem is, my objects are not only in front of / behind other objects. They’re sometimes partly both. Take a look at this example:


As you can see, the rear and the right corners should be partly in front of the yellow box and partly behind it. The yellow box is what I want to apply the effects on. The images below are the separate image layers I made until I realized the problem.

Is there a way to solve this?

You need to add the yellow cube as a Mask Layer in the Render Layer of the gray corners. You don’t need to duplicate the cube, just have it on two layers, one for it’s own Render Layer, and one to act as a mask in the gray corners’ Render Layer.

ETA:Here’s a screenshot. Note that in the 3D Viewport, the cube is selected on two different layers. One of those is used in the Mask Layer of the torus’s Render Layer.

ETA2: After playing around with it some more, you don’t even need the cube on two layers, just one. In the render layer for the torus, just select the cube layer in the Mask Layer section.


Steve S