Download

UE4.26:How to get the direction of specific directional lights in custom node material?

I have more than one directional light in level, I want to get the direction from a specific directional light,
how to code in custom node in UE4 material?
I’m using the version UE4.26 now~

I am assuming you want to know the vector of the light from any material, eg: you might want materials to have a specific path for being lit under a torch vs general-lighting?

If it was me I’d put the position of the light into a material-parameter-collection. Use a BP to grab the position of the torch and put it’s location in worldspace into the mpc. In the material, figure the vector you need from that position to whatever the material is on, etc, etc.

This is the same kind of trick that does the grass-bendyness via WPO as the character typically updates it’s position to an MPC so the grass-material can bend. Same deal here except you are sampling ‘somethings’ position for a lighting-path.

Thanks a lot first!
But not in this kind of situation.
I’m making a vedio.
In my level, there is a directional light for the environment,
and there are two lights for two different characters,
these characters are stylized characters ,
their face shadows are controlled by the direction of the directional lights .
I used different channels to make one light match one character,
but it doesn’t work,
the character will get a direction message from a random directional light in level.
So I replaced the light direction with three vectors!
And yes!I’m using MPC instead of light direction,
and marking different values on sequences,
so when the characters are moving,
the face shadows can get change together.

For what it is worth, if you’re using these directional lights as suns with the SkyAtmosphere system then you can get each light by their index in the material editor using the SkyAtmosphereLightDirection node, the light index option will be in the details panel.

Ok!Thanks ! I will try it when I meet some problems like this