# Make light visible once it passed through a transparent object

I am looking for a better solution to make light in Cycles only visible, once it passed through a transparent object.

Example which is actually pretty close but has a few flaws, see below

A doorframe seems to have an invisible lit room behind it.

Important:

• the cone in front of the door, so the light source needs to be a bit further back than the door itself
• the floor that is visible through the door should be lit too

what i did:

I created something like a corridor to block the light to the sides but still light the floor inside the doorframe. I took advantage of the isometric perspective to get away with a kind of wonky shape. The backside (opposite of the door) is just an emissive material.

The material for the corridor:

This method works, as long as there are no other light sources in the scene, which I need.

Problem: The corridor blocks the light from the right and casts a shadow.

Method 2:

No corridor this time, just a transparent door guiding the light.

Red is a transparent material, the yellowish meterial is my light source:

The problem is the missing cone in front of the door.

Any ideas on how I could improve my methods?

• did you enable portals in the light settings, because if not, that may be exactly what your looking for. Oct 27, 2020 at 13:47
• Although, portals are usually used for indoor scenes, I'm not sure how it would affect your scene, but might be worth a try Oct 27, 2020 at 13:49
• @JachymMichal Hi :). Basically what you can see in image 4 without the shadow from the corridor. There should be "outer" and "inner" light sources, the doorframe should cast a shadow. (i have my wonky light-blocking corridor for scenes, where there is no other lighting). Oct 30, 2020 at 8:53
• I feel like I'm beyond that starting point. But thanks anyways. Oct 30, 2020 at 9:53
• For a "one render pass" solution I'm pretty sure we would need either light linking or a smarter light path node (one that memorizes ray types throughout the whole path). So in the current state of Blender you have to composite 2 renders: one with your "portal" light source using a pitch black wall around the door and one with your normal light source, without the wall. You can then simply add the 2 renders together and you should get the right result. PS : if you also use an environment light, only use it on one of the 2 renders of course. Nov 1, 2020 at 4:14

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

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.

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.

• Nice one too Mr! Nov 1, 2020 at 11:13
• Here too... Both need a mask surrounding the portal instead of one inside it... still searching about that. Nov 1, 2020 at 11:14
• @lemon Doooh ! Slaps forehead really hard.. Ouch! Could use my OSL the other way round, and get round the back, by using a portal, as you say. Positively. Going to have to rewrite answer :D Nov 1, 2020 at 11:37
• @bstnhnsl Edited, to use positive portal instead of negative mask. Should be good for multiple portals. Nov 2, 2020 at 9:14
• @vklidu ..groan.. will you never give up? :D ... but seriously, you're right. Will revise when I feel a bit more refreshed, re. this Q ... Nov 2, 2020 at 9:57

It is not meant to be a serious answer, more like a solution on border of insolence :)
I lost patience, so I extrude a face for light on a floor :)

Light node tree

Divide node for a stupid to better incorporate colors.

As extension I tried to animate "floor light" according to light position. I just could not move Empty on edge and keep virtual center at zero coordinates at the same time. I will try to check that later.

• Immediate crash as soon as I use the Cycles rendering button if with CPU. But nice really! even if a bit faked. Don't think testing backfacing for the area light is useful? Nov 1, 2020 at 14:52
• 'Granny's Cure'.. (if it doesn't work, thump it!). Big fan. Especially for one-offs. :) Not every solution has to be a general-purpose tool. Nov 1, 2020 at 15:14
• @lemon I use CPU as well ... hmm. Thanks for point out the light, you'r right, not needed at all (light was brighter, but not natural). I think you noticed I don't have a clue what I'm doing here :) I just spent so much time here, so I wanted to post for fun. Nov 1, 2020 at 16:00
• @vklidu, for fun or not this is a good answer. But yes, transparency x light behavior is very strange... Nov 1, 2020 at 16:07
• Cool solution. Not really suitable for me. :) Nov 2, 2020 at 8:57

First solution using glass

A simple solution that may meet your need, but as @vklidu pointed me out in the comments, this is not working well with other lights.

The area where the light is placed is surrounded by a big box (selected below) with an open face where the portal is placed.

The node tree for this surrounding box is simply a "glass" with IOR set to one (flat transparency).

The light source (an area) also has a node tree:

It is emission shader except when the transmission depth (what comes from glass/transmissive materials) is at least 1.

Additionally, the surrounding box has a solidify modifier, as if not the light may go through it at the intersection with the floor plane.

There is some limitations, depending on the shape of the surrounding box (from which points of view you want to catch that).

Second solution, using transparency

The principle is the same with transparency instead of glass, but needs to fake a bit. But that allows other lights to work well it seems.

Here the mask object is extended along the floor to avoid light going outside of it where the mask meets the floor vertically.

So same mask shape as for @vklidu answer, thanks to him, but different node trees.

The nodes for the area lamp: