x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text alt text

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?

Product Version: UE 4.19
Tags:
lightvector1.jpg (163.9 kB)
lightvector.jpg (179.8 kB)
more ▼

asked Jan 03 '19 at 03:42 PM in Blueprint Scripting

avatar image

ReclusiveRychu
16 3 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

alt text

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

alt text

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.

more ▼

answered Jan 03 '19 at 04:53 PM

avatar image

ReclusiveRychu
16 3 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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: alt text

shoot.png (479.3 kB)
more ▼

answered Jan 03 '19 at 03:52 PM

avatar image

limijun
31 1 1

avatar image ReclusiveRychu Jan 03 '19 at 04:39 PM

Thanks for your quick response, but amazingly I discovered the answer, something that I thought would take me hours if not days to figure out was solved in a matter of minutes. I'm just astonished it worked! I'll create an answer for anyone else who might stumble upon this thread and have the same question.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question