Hi,
See the attached image - I have a basic setup so that the distance between 2 objects affects the emission material strength. I’m just trying to figure out how to make it the inverse. I would like it to be brighter when the sphere is closer (at the moment it is brighter when the sphere is further away). I’ve been playing around with some maths nodes and falloff nodes, I can’t figure it out.
Actually one quick follow-up. Do you know a way to make it so the emission is either 1 or 0 and nothing in between? Like past a certain distance, it just clicks over? Instead of a smooth gradient.
Cheers
I have kept the Brightness Factor input and the formula in the Expression Node is:
(x <= y) * z
Where X is the distance between the objects, Y is the cut-off distance and Z is the Brightness Factor. An expression like this:
(x <= y)
Returns True, or 1 if x is less than or equal to y and returns False, or 0 if x is greater than y. You can use these types of expression in Drivers as well. be aware that you cannot use = on its own - use == for “equals” and != for “not equals”
If you want the emission to be on outside the distance, just change the formula to:
(x > y) * z
Expression nodes are very useful and versatile in a node tree, for example you can put:
obj.matrix_world.decompose()
And it will return a list containing the True World Location, Rotation and Scale of an input object, even if it is parented to another object - you can use almost any line of Python code in fact.
OK I have one more question which I hope is just a tweak to the expression.
What if I want to make the brightness go between say 0 and 25 but I want to slide between this large range when the distance (of the two objects) changes only by a small amount? So do I need to use the Map node or something?
So I want to be able to slide an Empty object a small distance and it will turn the emission on from 0 to 25.
Thanks
OK now here is the next question: (haha this is never-ending!)
Imagine I have a series of boxes and I want to slide an empty down the line and they will light up and down in sequence.
So I have my nodes in place, now I am going to just Shift+D and duplicate the nodes (then push Shift+R a few times) and change the object and the material each time so everything is hooked up.
OK but the little I know about programming leads me to think I should be looking to avoid this manual work and instead implement a FOR loop or something. Is there any potential for doing this?
OK, so this you do with a Loop Sub-programme - feed a list of objects as the iterator and whatever parameters you want to effect the objects - all will be processed as if they were in a for… loop.
All is explained here, have a go and feel free to ask any questions.
If I was doing it I would use two of my own nodes - you can mimic these using Python scripts, and/or Python in Expression scripts, so the node tree is simply this:
As I move the Empty-Sphere, any cube, within 3.4 units, gets switched to the brighter material. Without my Material Nodes, it’s more complex, but quite doable.
Go to this page on my website, to look at how to use my material nodes, other pages explain how to install my add-on nodes.
Thank you very much sir!
I’m going to have a good read of the Subprogram and Loop documentation and also check out your website!
AN is very fun, I can imagine it has huge potential.
Yep, massive potential, I really like everything about it, I just made some more nodes to do things that are quite complex so I don’t have to remember how…
Cheers, Clock.
PS. type bpy.data.materials into an Expression node and you get a list of all the materials in your project.
Type [item for item in bpy.data.materials if item.name.startswith(‘green’)] and you get a list of all the materials that start with the letters “green”:
EDIT:
Feed an Expression node with an Object(obj) and a Material(mat) (Get List Element from my previous Expression node) type this in obj.material_slots[0].material = mat and it will set the material slot 0 to be the material.