2
$\begingroup$

I'm trying to make a cycles material for a planet in space, and I'm having trouble separating the dark-side of the planet from the light-side. I'm trying to relate it to the rotation of a sun lamp, such that I can mask it for daytime vs nighttime.

I've been trying drivers on the rotation fields of a vector mapping node, based on the rotation of my sun, but not having much luck.

$\endgroup$
0
$\begingroup$

I would do this by parenting an empty in line with the sun, then using the empty's coordinates as a vector in the node editor to get the sun's rotation.

First create an empty and parent it to the sun lamp. The empty should be directly in line with the sun lamp, but not exactly on top of it. To do this it helps to reset the sun's rotation (Alt+R) and put the empty somewhere directly underneath the lamp before parenting it, then re-position the lamp how you want it.

enter image description here

Next go to the node editor and add the following nodes. The output on the right will be the desired gradient from facing sun's direction 1.0 to facing directly away from the sun 0.0. The three Value nodes on the left are driven by the empty's X, Y, and Z positions respectively.

enter image description here

The position of the empty is converted to a vector using the Converter > Combine XYZ node, then normalized so that you don't have to worry about the distance from the lamp to the empty and scene units conversion to the node editor etc. The desired output is created by taking the dot product of this value and the geometry's normals.

Note that since I am using the dot product, this output will be a quadratic gradient. To get a linear gradient you will have to compute the vector similarity manually, or just use a color ramp or RGB curve node to create a satisfactory gradient.

$\endgroup$
  • $\begingroup$ For this to work, the sun lamp needs to be at world (0,0,0) right? $\endgroup$ – ajwood Mar 6 '16 at 20:57
  • $\begingroup$ @ajwood Yes. But now that I think of it, you could quite easily set up the drivers to get the empty's position relative to the sun lamp if you need to move it around. $\endgroup$ – PGmath Mar 6 '16 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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