How to render shadowmattes / phantom objects ...?

How can I render attached scene in a way that I only see the “complete” shadows cast by the two red squares? Key thing is that I also need the shadows rendered at locations where they normally would be covered by the red squares. But the squres and the background itself should not be visible. Basically setting all the objects to be phantom objects, that cast and receive shadows, but otherwise they are are not rendered.

How would i do this in touch?

You can simulate the desired look for one of the squares by turning off the depth test for phong1. but that workaround only works for one of the squares…
shaddowmatte.toe (7.79 KB)

If you use blending the objects will still cast shadow even if they are transparent. So setting their alpha to 0 (and rendering in farthest to closest) will result in what you want for casting shadows. For only being visible when having shadows casted on them, you can use GLSL shader and assign the output alpha based on what the shadowval is.