Light Vector based on Scene Object Position (Look At Constraint)
Okay so hopefully the title makes sense, if not I'll try to explain further. I have a sphere with a material that masks the unlit side of it. This gives me control over exactly where the texture stops instead of letting the scene lighting decide.
The light in my scene would move from one position to the other, and I easily changed this vector parameter using a lerp to go from one value to another. However my light source has changed so that it no longer moves in a vertical line but in a figure 8, and this makes things very tricky when changing the vector parameter in my material. I have to hard code in the exact vector positions.
Here's what I'm looking for: I want to have the parameter be based on the position of the light source in the scene similar to a 'Look at Constraint' in rigging terms. Wherever the light moves, the vector parameter will change to match. Is there any way to do this, or am I stuck hard coding it in?
asked Jan 03 '19 at 03:42 PM in Blueprint Scripting
Okay! So like... that was quick. I managed to figure out how to do this in a matter of minutes. So here's an explanation for anyone looking for the same solution.
So first what I did was make my directional light "Look At" my static material (I know a bit odd, but bare with me). Because my object with the material is not actually rotating, but instead it is the material that is "rotating" it can be used as the anchor for the directional light.
Super simple, I know, but it works. Oh by the way my directional light is following a spline that is shaped like a figure 8.
So then what I did was get the rotation of that directional light, convert it into a location vector, and then into a linear color variable. (I multiplied it by -1, because the vector was backwards).
Sorry for the blacked out things, I'm trying to be secretive haha. I created a dynamic material from the object in my scene with the specific material I wanted to change. Honestly don't think I needed to set a material instance variable in between those two, so I'll probably remove it. This works if all your objects are inside your blueprint. It's a similar process if they aren't but a little more work.
Hope this helps anyone who wants to do something similar to me.
answered Jan 03 '19 at 04:53 PM
emmm...maybe you can use Material Parameter Collection to store these "global" variables, and use them in your materials? when your light source moves, just change these variables in blueprint or c++ dynamically.
some simple material I create:
Follow this question
Once you sign in you will be able to subscribe for any updates here