14

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?

bstnhnsl
  • 2,690
  • 12
  • 29
  • did you enable portals in the light settings, because if not, that may be exactly what your looking for. – ETHAN DAY Oct 27 '20 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 – ETHAN DAY Oct 27 '20 at 13:49
  • another thing you could maybe try, is making a light area on the ground in front of the door, and shape it into a cone – ETHAN DAY Oct 27 '20 at 13:59
  • @ETHANDAY Portals are used to make light sampling more effective and to guide the raytracing. It won’t block any light. The cone lamp on the floor won’t have proper light falloff. – bstnhnsl Oct 27 '20 at 14:48
  • Hello :). What's the desired result if there are more lights in the scene? Should the doorframe cast any shadow at all? Or should all lights only shine through the transparent door? – jachym michal Oct 30 '20 at 08:42
  • 1
    @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). – bstnhnsl Oct 30 '20 at 08:53
  • I feel like Robin Betts' Magic Goggles answer could be a good starting point, but I can't figure it out myself :). – jachym michal Oct 30 '20 at 09:46
  • 1
    I feel like I'm beyond that starting point. But thanks anyways. – bstnhnsl Oct 30 '20 at 09:53
  • 2
    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.

    – ChameleonScales Nov 01 '20 at 04:14
  • https://imgur.com/a/A7WXHw5 is this ok? – Shantanu Aryan Nov 01 '20 at 08:32
  • @ChameleonScales I hope there will be a smart light path in a future update. Would solve a lot of my daily struggles... – bstnhnsl Nov 02 '20 at 07:02
  • @ShantanuAryan unfortunately that’s a solution i had in my early stages of exploring. – bstnhnsl Nov 02 '20 at 07:04
  • @ChameleonScales yes, it's annoying that the 'transparent depth' seems just to be an accumulator.. total number of transparent surfaces passed, at all stages. – Robin Betts Nov 02 '20 at 09:34

3 Answers3

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"

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

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • Nice one too Mr! – lemon Nov 01 '20 at 11:13
  • 1
    Here too... Both need a mask surrounding the portal instead of one inside it... still searching about that. – lemon Nov 01 '20 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 – Robin Betts Nov 01 '20 at 11:37
  • Did not test your osl. But yes if inverting it work, that will be more simple to use for @bstnhnsl – lemon Nov 01 '20 at 11:44
  • Well, this is a nice approach. My first thought was: well, this won't work if I'd like to have multiple doorways/portals in my scene. But i can just use my stupidly shaped corridor from my first approach. My camera won't ever move so this is actually almost perfect (my cpu is rubbish compared to the GPU, so using OSL isn't great). 98/100 (Y) – bstnhnsl Nov 02 '20 at 08:44
  • 1
    @bstnhnsl Edited, to use positive portal instead of negative mask. Should be good for multiple portals. – Robin Betts Nov 02 '20 at 09:14
  • @RobinBetts very cool! thanks. Really like that you can even look through the portal from the other side. I don't need that, but thats awesome (and maybe helpful for others). – bstnhnsl Nov 02 '20 at 09:51
  • 1
    @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 ... – Robin Betts Nov 02 '20 at 09:57
  • @vklidu personally, I think compositing is a much better way, if you can.. it leaves so much more flexibility.. and by the time you've burned up time on your CPU....... – Robin Betts Nov 02 '20 at 11:17
  • Yes but also a lot of inaccuracy in compositing on a pixel level, especially in mixing light coming from scene to scene. Never mind, great solution :) – vklidu Nov 02 '20 at 11:33
  • I have a somewhat similar question about portals and OSL, mostly about the language, can you take a look? https://blender.stackexchange.com/questions/228809/aperture-science-portals-using-osl – TheLabCat Jul 01 '21 at 18:05
7

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

lemon
  • 60,295
  • 3
  • 66
  • 136
7

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.

vklidu
  • 36,165
  • 1
  • 61
  • 135
  • 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? – lemon Nov 01 '20 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. – Robin Betts Nov 01 '20 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. – vklidu Nov 01 '20 at 16:00
  • @vklidu, for fun or not this is a good answer. But yes, transparency x light behavior is very strange... – lemon Nov 01 '20 at 16:07
  • @RobinBetts Haha :) Yep :) :) Any hint how to copy negative location? Like now when Light and Empty are not the same distance from world origin, the center point is not at zero X location (I need like Light Y=6 and Empty Y=-16). Thanks – vklidu Nov 01 '20 at 16:12
  • 1
    Cool solution. Not really suitable for me. :) – bstnhnsl Nov 02 '20 at 08:57