2
$\begingroup$

I'm using cycles and have a texture that I want to animate by changing the hue so that it cycles through the rainbow. I know how to make keyframes of nodes, however I'm not sure how to make it seamless when the hue slider operates on a 0-1 scale. Would it just be a matter of changing the animation curves??

$\endgroup$
2
$\begingroup$

You can use a Maths node set to 'Modulo' to convert an input value into a repeating range; the output will vary between 0 and the value set on the second input. For example, with the following nodes :

hue continuous

Varying the 'Value' will produce Hue that varies between 0 and 1, then restarts back at 0. This will produce a continuous repeating range of hues as Value increases from 0 upwards (simply keyframe Value from 0 to, say, 5 to result in 5 repetitions of the range of hues : 0.0->1.0, 0.0->1.0, 0.0->1.0, 0.0->1.0, 0.0->1.0).


As @RobinBetts pointed out, using the Modulo function can cause strange effects then using negative values as the Blender 'Modulo' function (as is the same for many programming languages) flips the output for negative input values. To correct this we can add a couple of additional Maths nodes :

For example, here's the usual output from the Modulo function :

modulo

Notice how the output flips in the centre as it crosses zero.

Adding Maths nodes to Add the Value, followed by a second Modulo corrects for this - by effectively shifting all values that are less than zero back to being positive :

modulo - fixed

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ I was trying this earlier this evening, and it seems to raise an anomaly, crossing zero. In Python, -0.3 mod 1 == 0.7 mod 1, so you get a sawtooth, continuous down the number line. I doesn't seem to be so with the modulo math node? The results of -.3 and .7 are different? I think in the node, the sawtooth reflects about / rounds towards 0, where Python rounds toward -infinity. .. see here $\endgroup$ – Robin Betts Nov 12 '18 at 0:14
  • 1
    $\begingroup$ @RobinBetts Yes - staying to positives would certainly avoid the problem. I presume from the question that won't be a problem since it's just some arbitrary value that's being animated. However, by adding a couple of additional maths nodes you can avoid the problem of negatives - see edit. $\endgroup$ – Rich Sedman Nov 12 '18 at 17:41
  • 1
    $\begingroup$ Cunning. I spent quite a time trying to figure out how to fix this in a snappy way...... I thought it probably wouldn't take you long.... Glad I didn't put my clumsy solution up :D... also quite important for procedural textures, etc. $\endgroup$ – Robin Betts Nov 12 '18 at 18:09
  • 1
    $\begingroup$ @RobinBetts I’ll raise it - it looks quite convincing to me. As an example, consider 0.00001 mod 10, -0.00001 mod 10, 0 mod 10 - all values very close to each other. Using the Node implementation you’ll get results of 0.00001 for the first, -0.00001 for the second and -10 for the third - wildly different but they should actually all be very close. $\endgroup$ – Rich Sedman Sep 17 '19 at 8:19
  • 1
    $\begingroup$ I’ve put together an example that visualises it quite convincingly (I’ll update the answer when I get chance). $\endgroup$ – Rich Sedman Sep 17 '19 at 8:19

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.