# How can I move an object on a separate layer behind another in the compositor?

How can I make the light bar, after compositing (applying the blur effect on it), be displayed behind the ball, not in front of it?

• First off, recognize the reason why it's doing this - or appearing to. It's because you're using the Add blend mode, and your bar is quite light. That realization will help you find the solution (use alpha over, etc.) – wchargin Oct 2 '13 at 0:37

Expanding on Gunslinger's answer, this can be done on two render layers, using an ID Mask node:

1. With the foreground object selected, set the Pass index to 1 in Object properties > Relations:

2. Enable the Object index pass in Render Layers > Passes:

3. Add an ID Mask node and set the Index to 1.

4. Plug the IndexOB output from the Renderlayer node into the ID Mask node. This will provide a mask for the foreground object:

5. Mix:

Gunslinger's setup is better as it preserves the sky:

## Result:

Note that you can also use ID masks on a material basis.
Enable Material index in Render layers > Passes, and set the pass index for the material:

Use Materials > Settings > Pass index to set the pass index of the material in Cycles:

Or in Blender internal use Materials > Options > Pass index:

If, you are rendering with Blender Internal, one way to go about this is to go to the render layers with the ball and the bar and under Layer, untick Sky for both. Since this will remove the background from both those layers, just create another RenderLayer that will just be the sky.

Now if you use an Alpha Over node, you can choose which object appears over which one by switching the inputs. You will then use another Alpha Over node to get back the background.

For Cycles, you can get the same results by making sure that Use Environment is ticked under Layer and then ticking Transparent under Film, this will affect all render layers however it seems so perhaps you can use an image as the second input for the second Alhpa Over node, just render out a nice gradient etc and load it back in as an image.

• Thanks. But unticking Sky for them make their backgrounds black not transparent. On the other hand, ticking Transparent under Film make the three layers' backgrounds transparent. – Jikk Sep 26 '13 at 17:21
• Not sure how you're getting that, it should be transparent. Try going to Render > Output and changing it from RGB to RGBA. If that doesn't do anything, please upload and share the blend-file, it is possible you changed something elsewhere. – iKlsR Sep 26 '13 at 17:37
• docs.google.com/file/d/0B64HAX4F6H-YTmlra0otX3VXckE/… – Jikk Sep 26 '13 at 18:06
• @Jikk In the future, please specify what render engine you are using. I very rarely use Cycles so i'm not able to really help in regards to that and it seems that this doesn't work so i'm not sure. This answer only applies to the Internal Renderer. – iKlsR Sep 26 '13 at 18:19
• @Jikk It would be best if you asked that as a separate question as you are more likely to get better answers that way. I added a simple workaround if using Cycles to the answer, did you try that? Also see, Can I use Cycles materials with Blender Internal?. If the answers seem confusing, please use the comments section to request clarification from the authors. :) – iKlsR Sep 28 '13 at 16:45

Another way to do this would be to render another pass with only the ball, call it mask. Override the material to be pure black.

Multiply the line with this renderpass. Before or after the blur node if you want the glow to overlap the ball slightly, or not.

Note! (if I have time tonite, I will update the screenshot). The background of the mask must of course be white, else it will dim the line.

Node setup here:

• Instead of rerendering the ball/cube, why not use a id mask node with a object or material index? – gandalf3 Sep 26 '13 at 19:37
• You are right. I just couldn't figure it out. – Gunslinger Sep 27 '13 at 6:07