14
$\begingroup$

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

enter image description here

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.

enter image description here

The material for the corridor:

enter image description here

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

enter image description here

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.

enter image description here

enter image description here

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

enter image description here

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

Any ideas on how I could improve my methods?

$\endgroup$
13
  • $\begingroup$ did you enable portals in the light settings, because if not, that may be exactly what your looking for. $\endgroup$
    – ETHAN DAY
    Commented Oct 27, 2020 at 13:47
  • $\begingroup$ Although, portals are usually used for indoor scenes, I'm not sure how it would affect your scene, but might be worth a try $\endgroup$
    – ETHAN DAY
    Commented Oct 27, 2020 at 13:49
  • 1
    $\begingroup$ @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). $\endgroup$
    – bstnhnsl
    Commented Oct 30, 2020 at 8:53
  • 1
    $\begingroup$ I feel like I'm beyond that starting point. But thanks anyways. $\endgroup$
    – bstnhnsl
    Commented Oct 30, 2020 at 9:53
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Nov 1, 2020 at 4:14

3 Answers 3

14
+100
$\begingroup$

(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

$\endgroup$
11
  • $\begingroup$ Nice one too Mr! $\endgroup$
    – lemon
    Commented Nov 1, 2020 at 11:13
  • 1
    $\begingroup$ Here too... Both need a mask surrounding the portal instead of one inside it... still searching about that. $\endgroup$
    – lemon
    Commented Nov 1, 2020 at 11:14
  • $\begingroup$ @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 $\endgroup$
    – Robin Betts
    Commented Nov 1, 2020 at 11:37
  • 1
    $\begingroup$ @bstnhnsl Edited, to use positive portal instead of negative mask. Should be good for multiple portals. $\endgroup$
    – Robin Betts
    Commented Nov 2, 2020 at 9:14
  • 1
    $\begingroup$ @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 ... $\endgroup$
    – Robin Betts
    Commented Nov 2, 2020 at 9:57
7
$\begingroup$

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.

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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.

enter image description here

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.

enter image description here

The nodes for the area lamp:

enter image description here

The ones for the mask:

enter image description here

$\endgroup$
2
  • $\begingroup$ Bravo! Very neat, and might do exactly what the @bstnhnsl is looking for. $\endgroup$
    – Robin Betts
    Commented Nov 1, 2020 at 11:05
  • 1
    $\begingroup$ @vklidu, I know and agree... environment lighting does not work well either. Still thinking about it. But thanks. $\endgroup$
    – lemon
    Commented Nov 1, 2020 at 14:12
7
$\begingroup$

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 :)


enter image description here enter image description here enter image description here

Light node tree enter image description here

Divide node for a stupid to better incorporate colors. enter image description here


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.

$\endgroup$
6
  • $\begingroup$ 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? $\endgroup$
    – lemon
    Commented Nov 1, 2020 at 14:52
  • $\begingroup$ '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. $\endgroup$
    – Robin Betts
    Commented Nov 1, 2020 at 15:14
  • $\begingroup$ @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. $\endgroup$
    – vklidu
    Commented Nov 1, 2020 at 16:00
  • $\begingroup$ @vklidu, for fun or not this is a good answer. But yes, transparency x light behavior is very strange... $\endgroup$
    – lemon
    Commented Nov 1, 2020 at 16:07
  • 1
    $\begingroup$ Cool solution. Not really suitable for me. :) $\endgroup$
    – bstnhnsl
    Commented Nov 2, 2020 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .