1
$\begingroup$

Improving on this tutorial, is there a way to animate the gradient so the colours move across the object?

$\endgroup$
1
  • $\begingroup$ if I have configured the material of the cube as described above, how do I execute the animation? Unfortunately I can't get the colors to move. Many thanks for the help ! $\endgroup$ – klausb Jan 31 '19 at 15:32
5
$\begingroup$

This can be achieved by animating the Location in the Mapping node, and adding a few math nodes between the Separate XYZ node and the ColorRamp node, like this:

enter image description here

The ColorRamp uses values between 0 and 1, and if you input anything outside this range, it gets clamped (i.e. anything greater than 1 becomes 1, and anything less than 0 becomes 0). These math nodes make sure you get a value in the expected range.

The Modulo node with the lower value set to 1, basically preserves only what comes after the decimal point, i.e. 1.5, 2.5, 3.5 and so on all become 0.5, and -1.5, -2.5, -3.5 and so on all become -0.5. So this gives us a value in the range -1 to 1.

The Less Than node with the lower value set to 0 outputs 1 if the upper input is below 0 and 0 if it's equal to or greater than 0.

The Add node simply adds the output from the Modulo and the Less Than nodes, thus fixing negative values. So now we have a value in the expected range.

enter image description here

To animate, hold the mouse pointer over the Location properties in the mapping node, and either press I or right click and select Insert Keyframes or Insert Single Keyframe. The former adds keyframes to all three location properties and the latter adds a keyframe to the one the mouse pointer is on. Move the timeline a number of frames, change the appropriate location value(s) and add keyframes again. Repeat as many times as needed.
N.B. The nodes above only affect the Z location. It can easily be changed to either the X or Y location, by using the corresponding output from the Separate XYZ.

$\endgroup$

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.