I'm trying to make a realistic earth but now comes the problem of the lights. Since I'd like to make an animation I want the night lights(which are just a texture with an emission shader) to "appear" only where the light does not hit the earth.

This is the situation with the earth material

I really think I just have to plug something into that fac input but I don't know what.

enter image description here

When I'll make the earth rotate I want the lights to stay only where the light does not hit the sphere. Please Help me out here, I tried everything.

  • I get what you mean, however, I saw that there are other ways to do it without using the light paths (which is impossible) but using the sun orientation and the earth orientation with a dot product. That doesn't work for me though, I don't know why... – Aletag Aug 19 at 17:58
up vote 0 down vote accepted

Because the planet is a sphere, with no irregular self-shadowing, you can use a simple mask, in another object's space.

In this example, the planet is at the global origin, rotating about Z. Its diameter is 2 units. The sun is down positive X.

Add an Empty at the center of the planet. (Its local positive X points toward the sun). It will not rotate, while the planet does, and the mask between emissive and invisible lights will be in the empty's Object Space, not moving.

The lights texture is in the planet's Object Space, and turns with the planet.

A simple Black/White transition is made by a Color Ramp, down the X of the empty, and centered on it, to make the mask. Dimensions may have to be changed, depending on your model.

So the tree is something like this:

enter image description here

(You will obviously be using your own textures, not procedural lights, as shown here, so those nodes don't matter)

With this sort of result:

enter image description here

If you're animating the planet going round the sun, you could parent the Empty to the sun, and the mask will stay pointing in the right direction..

or, in other circumstances, you could constrain the Empty to point its X at the sun in another way.

  • Wow, that worked man! Thank you so much, it was a great idea! However, the line that splits the dark and the lit section is not so smooth for me, I don't know if you have any idea, you solved my problem though. – Aletag Aug 20 at 15:42
  • I found that I was getting lighting artifacts if I used a point light at a great distance and high strength for the sun, so I wound up using a sun lamp instead.. But that really doesn't have anything to do with the shaders. The edge of the mask is procedural... should be fine. How high a resolution is your 'lights' texture? How smooth is your planet? – Robin Betts Aug 20 at 17:36
  • 1
    That's really not a big deal, I think I just made a mistake, I can't even notice it an more – Aletag Aug 22 at 15:22

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.