Here is an “impossible cube” done with compositing nodes. (And with apologies for the wretched textures and materials …)
All of the objects are on layer #1 (first RenderLayer). The vertical board is also in layer #2 (second), and the horizontal board is also in layer #3 (third RenderLayer). The trick is done by using AlphaOver to superimpose the vertical board a second time using the horizontal board as an alpha-mask.
The small viewer (and the associated second AlphaOver node) illustrates the square of material that is superimposed. (It is, of course, the exact bit of pixels that tell you what’s “in front of” what.)
If you’re paying attention, you’ll notice that the shadows don’t quite match the apparent topology. And this is why the lighting in such pictures is usually so “forced,” so that any inconsistencies are eliminated. (Yes, the cube is barely “floating in mid-air.”)
And here is: impossible.blend (538 KB). (Blender 2.57.0; OS/X.)