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.

  • $\begingroup$ blender.stackexchange.com/questions/86775/… $\endgroup$ Aug 19, 2018 at 14:35
  • $\begingroup$ 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... $\endgroup$
    – Aletag
    Aug 19, 2018 at 17:58

2 Answers 2


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.

  • $\begingroup$ 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. $\endgroup$
    – Aletag
    Aug 20, 2018 at 15:42
  • $\begingroup$ 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? $\endgroup$
    – Robin Betts
    Aug 20, 2018 at 17:36
  • 1
    $\begingroup$ That's really not a big deal, I think I just made a mistake, I can't even notice it an more $\endgroup$
    – Aletag
    Aug 22, 2018 at 15:22

I spent the better part of the day trying to figure out how to do this, and finally got it to work.

Here is my proposed solution:

Node and driver setup

It is using:

  • the initial sphere for the material
  • an empty that should be placed at the center of the sphere (not parented, you may use a constraint instead if you plan to move the sphere)
  • a sun lamp
  • 3 drivers to check out the rotation of the sun object and use it to determine the "shadowed" part of sphere

To create the drivers:

  • select the rotation X of Vector Mapping node
  • right click and select "Add driver"
  • check Type: Averaged Value (optional)
  • click Object and select the sun object
  • select the Type X rotation just below
  • (you may need to click on "Update Dependencies")
  • repeat for Y and Z properties

(Also, don't forget to set the Vector mapping Z value to -1)

Quick render of the example

Animated example

.blend file available:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .