Got it — so you do need those background pixels.
Unfortunately, I think you will need 3 copies of your comp — one for background, one for midground, and one for foreground. Before you start duplicating, I’d recommend a scheme for identifying/grouping the layers. If you use label colors (for example all FG Red, all MG Green, all BG blue), then you can click the label next to the comp index/name and choose “Select Label Group” from the context menu to get the whole group. (Alternately, you could use the Name or Comment fields, including FG/MG/BG in each layer name or comment, then use the search field to make it easier to select only the elements in that render layer.)
You can set the “Cast Shadow – Only” on one layer, copy the property from the timeline, multi-select the rest of the layers you want as above, and paste to save a lot of time.
To apply the alpha from a single layer across a whole bunch of them — like restricting your FG layers to a surface in the pixel map — you can cut out the surface from the mask, put the mask as the top-most layer, then use the Stencil Alpha blend mode.
Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive | RenderBreak [blog] | Profile [LinkedIn]