(This answer revised thanks to @lemon pointing out what should have been obvious..)
If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script script might be a tool to add to your box:. By tracing back down the incoming ray to a light, it returns information about the object being lit. It's not all used in this example, but might be useful if you go for a different effect.
#include "stdosl.h"
shader LitObjectIDX(
output float ObjectIdx = 0.0,
output float MaterialIdx = 0.0,
output vector LitP = 0.0,
output vector LitN = 0.0
)
{
if (trace(P,I)){
getmessage("trace", "object:index", ObjectIdx);
getmessage("trace", "material:index", MaterialIdx);
getmessage("trace", "P", LitP);
getmessage("trace", "N", LitN);
}
}
It casts a ray back down the incoming direction,ObjectIdx
and returns information aboutMaterialIdx
are the object that it finds there. In this case, it yieldsPass Index settings for the Pass Index of that object and material being lit. It can be used in a shader for a light to modifyLitP
and LitN
are the light's behaviour according tolocation and the object it's lighting.
In this example, a screen is erected acrossnormal of the scene...
... with a gaplit point, in it for the doorWorld space.
The screen is made Make a 'Portal' plane, of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on transparent material, so it's invisible to most lightsoccupying the doorway. ButFor this tree, if we give the objectit a Pass Index of, say, 20 in its Object > Relations panel. You could use other indices, It can be persuaded to cast shadows for any light with these nodes:
In this caseThis node set-up for the Transparent Depth (>0) also ensures we can't seeyellow through-light restricts the effects oflighting to the lightportal itself, and areas seen throughthrough the screenportal, contrasting those seen from behind and those seen from in front.
So Since writing, whenyou've told me that the yellow light usescamera doesn't need to move, so the nodessecond restriction, (most of the overallbottom branch) is not required. Just use the Transparent Depth on its own. My effect can be this:looks a bit odd, anyway.
ThisThe attached .blend is limited: taking the camera behind the screen gives the game away, buta bit more complex than needed just to illustrate this method.. you might be ablewould probably just want to use the script in ways more precisely geared, one way or another, to the effect you're looking forsuit your particular purposes.