4

I know I can separate RGB into 3 branches and assign different functions to each one. This selecting method doesn't work if there are white lights in the scene so I need to add an additional criteria to make this system work. Can I add a criteria that the light has to be at a certain distance from an empty?

Can I do the node version of this?:
Does the light (have a value in the RED channel) AND is the light (distance of empty > 1km) then 1 else 0.

Eric Huelin
  • 2,251
  • 7
  • 38
  • 73
  • Are you talking about shading the light, or the lit object? Is this RGB separation for NPR purposes ( à la Lightning Boy?) – Robin Betts Feb 08 '22 at 19:38
  • Apart from already quite good answers here so far it would be very nice of you to explain what you want to achieve. Where do you want to use the result of this if RED > 0 and Distance > 1000 then 1 else 0 function? For the light? For a material of another object? In a Geometry Nodes node tree? Because you can do it different ways depending on what you want and in the answers there seems to bit of confusion on how to deal with the light or the RGB channels... – Gordon Brinkmann Feb 09 '22 at 07:15

2 Answers2

4

Of course you can!

That's a pretty good use case for drivers.

Drivers are made for setting a property depending on other criteria (e.g. other properties, variables, the weather ...whatever).

So for your case (it is not exactly yours, it is just to guide you) use this:

enter image description here

The input variables (can be more one or more or none) are the tools to calculate your results. In this case: the distance between light and cube.

The expression evaluates/calculates the result.

In this case: if the distance is bigger than 1, red will be 0. If it is lower or equal than 1, it will be 1.

result:

enter image description here

Here an example with 2 inputs and an "and"-clause:

enter image description here

result:

enter image description here

Chris
  • 59,454
  • 6
  • 30
  • 84
  • If I use this solution, I'll need to know how a driver can affect a node, and I'll have to ask how to do that. – Eric Huelin Feb 08 '22 at 13:54
  • maybe check out some beginner driver tutorials like this one: https://youtu.be/57VGk_7I69M after that my answer is hopefully easier to understand – Chris Feb 08 '22 at 14:00
  • @EricHuelin It could also be useful to know where you want to use the result - in a node tree of the light itself or in the material of some other object. I would usually use Chris' driver solution, but if you want to use it in the light's node tree you can get away without using drivers. – Gordon Brinkmann Feb 08 '22 at 14:16
4

You can do this with just 5 nodes.

  1. In Texture Coordinates target the empty
  2. Add Vector Math > Length
  3. In Math > Less Than specify the threshold in meters

Once the light is closer than 1 meter it lights up enter image description here

jachym michal
  • 31,744
  • 5
  • 55
  • 115
  • 1
    But that's not checking if the RGB channel has a value > 0 for red as I understand this sentence: "Does the light (have a value in the RED channel) AND [...]" – Gordon Brinkmann Feb 08 '22 at 12:50
  • 1
    True :). I was going from the question subject and this "Can I add a criteria that the light has to be at a certain distance from an empty?" to focus on one problem at a time ;) – jachym michal Feb 08 '22 at 12:53
  • 1
    I guess the RGB channel thing will not work solely in nodes if you want to use it in a different object since I don't see a way how to get the light's RGB value into another material without drivers > so I would prefer Chris' solution (although if the OP is unexperienced with drivers it could be tricky to extract the RGB information from the light). But if you're using the light with nodes and need the information in there, a completely node-based version like you started would be possible. – Gordon Brinkmann Feb 08 '22 at 13:00
  • 1
    Also noteworthy: you're using a Vector Math > Length node instead of Distance. This saves you one Texture Coordinate node, but if you do so the result can change without moving the light or the empty away, just by scaling the empty, whereas Distance calculates the distance from one object's origin to the other, regardless of scale. But even Distance will also give different results depending on if you target the light itself in the second Texture Coordinate node or leave it empty. – Gordon Brinkmann Feb 08 '22 at 16:47
  • 1
    Hey :). Thanks for checking the anwer so thoroughly, I'll correct the inconsistencies – jachym michal Feb 08 '22 at 16:51
  • 1
    I'm just a bit experimenting for myself... I just noticed it by coincidence - when I'm using the Distance calculation and take the object coordinate of the empty and the one of the light, and I've set a Greater Than node with a threshold of 4, than it immediately turns true as soon as the distance is 4 (which actually is "greater or equal than 4", not "greater than") whereas when I leave the target blank for the light, it turns true only when the distance is greater than 4.4, which is much too late. – Gordon Brinkmann Feb 08 '22 at 17:05