How to dynamically change the light direction of a planet material.

Hey everyone,

So recently i’ve been following a tutorial on how to make a planet material but i wanted to take it one step further and actually change the incoming light’s direction dynamically, because now the only thing i can do is change it manually from the material instance menu as seen in the screenshot below.

What i originally thought of doing was to somehow change the vector colour automatically from inside the material with maybe a material function and somehow parametrize the speed at which the colour would change, however i didn’t really figure out how I could do that (still learning ue4), I also thought that this might be possible through blueprints and/or a parameter collection + timeline.

This is the part in the master material that i’m trying to automatically change.

What i was trying to achieve was to actually make the light follow the sun (which I would add later) 's movement and light the earth accordingly instead of just staying static as seen in the picture. I’m guessing this would be better explained with a gif but i didn’t know how to upload one. I’m sorry if i didn’t explain very well what i’m after but this is the best way i found to explain it.

Thanks in advance to anyone that answers.

P.S. Sorry if this is in the wrong section of the forum i didn’t know under which category this should be posted.

if the sun is object in the world, and planet moves around it, you can find direction by formula:

LightDirection = Normalize(PlanetLocation - SunLocation)

Now you need to pass this value to that material using DynamicMaterialInstance in blueprint.

Ok I’ll try that out next time I work on the project, it seems like it should work, in the meanwhile I also got an answer from the creator of the tutorial giving me another solution as well. Thanks very much for your help. Much appreciated.

Hi,

can you share the other answer please?

Could you provide any more info on what that looks like in the shader please?

Well it wasn’t exactly an in depth answer, he suggested that if the sun is another object in the scene that’s rotating around the earth I could get the forward vector of the sun and transfer that value to the earth material through blueprints by making it a dynamic material instance. I still didn’t get a chance to try it out though. Althought i’m positive that it should work out that way. I can post a screenshot of the blueprint when it’s done If you want.

That was the solution from DrunkenPenguin, it’s kind of the same with this one just explained differently :p, he told me he had tried it out back in 2015 but didn’t exactly remember how he did it and didn’t have a shader he could share so I should try it out to confirm it. I asked him in the comment section you should be able to find the comment if you want.

Thanks for your reply. BTW what was the other solution you got from the original tutorial guy, was it DrunknPenguin?

I’ve dropped him a message.

Thanks for replying :slight_smile:

You’re welcome, glad I could help somehow. :slight_smile: