Skip to main content
Bounty Ended with 100 reputation awarded by bstnhnsl
@lemon pointed out - no mask required
Source Link
Robin Betts
  • 78.8k
  • 10
  • 79
  • 199

(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...

enter image description here

... with a gaplit point, in it for the doorWorld space.

enter image description here

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:

enter image description hereother portals.

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.

enter image description hereenter image description here

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.

enter image description here

If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script might be a tool to add to your box:

#include "stdosl.h"

shader LitObjectIDX(  
         output float ObjectIdx = 0.0        
)
{  

    if (trace(P,I)){
        getmessage("trace", "object:index", ObjectIdx);
    }
}

It casts a ray back down the incoming direction, and returns information about the object that it finds there. In this case, it yields the Pass Index of that object. It can be used in a shader for a light to modify the light's behaviour according to the object it's lighting.

In this example, a screen is erected across the scene...

enter image description here

... with a gap in it for the door.

enter image description here

The screen is made of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on, so it's invisible to most lights. But, if we give the object a Pass Index of, say, 20, It can be persuaded to cast shadows for any light with these nodes:

enter image description here

In this case the Transparent Depth (>0) also ensures we can't see the effects of the light seen through the screen.

So, when the yellow light uses the nodes, the overall effect can be this:

enter image description here

This is limited: taking the camera behind the screen gives the game away, but you might be able to use the script in ways more precisely geared to the effect you're looking for.

(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 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);  
    }
}

ObjectIdx and MaterialIdx are the Pass Index settings for the object and material being lit. LitP and LitN are the location and the normal of the lit point, in World space.

Make a 'Portal' plane, of ordinary fully transparent material, occupying the doorway. For this tree, give it a Pass Index of 20 in its Object > Relations panel. You could use other indices, for other portals.

This node set-up for the yellow through-light restricts the lighting to the portal itself, and areas seen through the portal, contrasting those seen from behind and those seen from in front. Since writing, you've told me that the camera doesn't need to move, so the second restriction, (most of the bottom branch) is not required. Just use the Transparent Depth on its own. My effect looks a bit odd, anyway.

enter image description here

The attached .blend is a bit more complex than needed just to illustrate this method.. you would probably just want to use the script, one way or another, to suit your particular purposes.

enter image description here

added 8 characters in body
Source Link
Robin Betts
  • 78.8k
  • 10
  • 79
  • 199

If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script might be a tool to add to your box:

#include "stdosl.h"

shader LitObjectIDX(  
         output float ObjectIdx = 0.0        
)
{  

    if (trace(P,I)){
        getmessage("trace", "object:index", ObjectIdx);
    }
}

It casts a ray back down the incoming direction, and returns information about the object that it finds there. In this case, it yields the Pass Index of that object. It can be used in a shader for a light to modify the light's behaviour according to the object it's lighting.

In this example, a screen is erected across the scene...

enter image description here

... with a gap in it for the door.

enter image description here

The screen is made of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on, so it's invisible to most lights. But, if we give itthe object a Pass Index of, say, 20, It can be persuaded to cast shadows for any light with these nodes:

enter image description here

In this case the Transparent Depth (>0) also ensures we can't see the effects of the light seen through the screen.

So, when the yellow light uses the nodes, the overall effect can be this:

enter image description here

This is limited: taking the camera behind the screen gives the game away, but you might be able to use the script in ways more precisely geared to the effect you're looking for.

If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script might be a tool to add to your box:

#include "stdosl.h"

shader LitObjectIDX(  
         output float ObjectIdx = 0.0        
)
{  

    if (trace(P,I)){
        getmessage("trace", "object:index", ObjectIdx);
    }
}

It casts a ray back down the incoming direction, and returns information about the object that it finds there. In this case, it yields the Pass Index of that object. It can be used in a shader for a light to modify the light's behaviour according to the object it's lighting.

In this example, a screen is erected across the scene...

enter image description here

... with a gap in it for the door.

enter image description here

The screen is made of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on, so it's invisible to most lights. But, if we give it a Pass Index of, say, 20, It can be persuaded to cast shadows for any light with these nodes:

enter image description here

In this case the Transparent Depth (>0) also ensures we can't see the effects of the light seen through the screen.

So, when the yellow light uses the nodes, the overall effect can be this:

enter image description here

This is limited: taking the camera behind the screen gives the game away, but you might be able to use the script in ways more precisely geared to the effect you're looking for.

If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script might be a tool to add to your box:

#include "stdosl.h"

shader LitObjectIDX(  
         output float ObjectIdx = 0.0        
)
{  

    if (trace(P,I)){
        getmessage("trace", "object:index", ObjectIdx);
    }
}

It casts a ray back down the incoming direction, and returns information about the object that it finds there. In this case, it yields the Pass Index of that object. It can be used in a shader for a light to modify the light's behaviour according to the object it's lighting.

In this example, a screen is erected across the scene...

enter image description here

... with a gap in it for the door.

enter image description here

The screen is made of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on, so it's invisible to most lights. But, if we give the object a Pass Index of, say, 20, It can be persuaded to cast shadows for any light with these nodes:

enter image description here

In this case the Transparent Depth (>0) also ensures we can't see the effects of the light seen through the screen.

So, when the yellow light uses the nodes, the overall effect can be this:

enter image description here

This is limited: taking the camera behind the screen gives the game away, but you might be able to use the script in ways more precisely geared to the effect you're looking for.

Source Link
Robin Betts
  • 78.8k
  • 10
  • 79
  • 199

If you're prepared to use OSL, (and therefore the CPU for rendering,) this little script might be a tool to add to your box:

#include "stdosl.h"

shader LitObjectIDX(  
         output float ObjectIdx = 0.0        
)
{  

    if (trace(P,I)){
        getmessage("trace", "object:index", ObjectIdx);
    }
}

It casts a ray back down the incoming direction, and returns information about the object that it finds there. In this case, it yields the Pass Index of that object. It can be used in a shader for a light to modify the light's behaviour according to the object it's lighting.

In this example, a screen is erected across the scene...

enter image description here

... with a gap in it for the door.

enter image description here

The screen is made of an ordinary fully-transparent BSDF, with 'Transparent Shadows' on, so it's invisible to most lights. But, if we give it a Pass Index of, say, 20, It can be persuaded to cast shadows for any light with these nodes:

enter image description here

In this case the Transparent Depth (>0) also ensures we can't see the effects of the light seen through the screen.

So, when the yellow light uses the nodes, the overall effect can be this:

enter image description here

This is limited: taking the camera behind the screen gives the game away, but you might be able to use the script in ways more precisely geared to the effect you're looking for.