5
$\begingroup$

The Image Texture node has setting (selected by default) to Repeat. How can I get that effect on a ColorRamp?

The node setup below illustrates how the ColorRamp node behaves differently from the Image Texture node. Slide the MixRGB node to 0 to see the texture, or 1 to see the gradient. Once you have seen both - gradually drag the number in the Value node to see how this affects the texture and the gradient differently.

enter image description here

For the texture, a value of 1 gives the same result as a value of 5. A value of -1.75 gives the same result as a value of 3.25 - that is to say anything higher that 1.0 or lower than 0.0 wraps back around.

For the gradient of the ColorRamp, dragging the Value slider in either direction causes the color at the edge (magenta in this case) to stretch.

Is there a way to use Math nodes or something to create a repeating wrap for a ColorRamp gradient like the Image Texture node can produce?

(And yes, it has occurred to me that I can prepare a texture of a gradient and use that, but if the ColorRamp node can be used, preparing such images will not be necessary.)

$\endgroup$
7
$\begingroup$

You can use a Math node set to Wrap (as you suggested). You might need to use one of the lastest versions in order to see it, it has been added later than V.2.80 if memory serves. According to the docs :

Outputs a value between Min and Max based on the absolute difference between the input value and the nearest integer multiple of Max less than the value.

Set the Max to 1 and Min to 0.

enter image description here

Alternatively, you can Wrap the whole 3D space before separating the axes with a Vector Math node set to Wrap.

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ Thank you! Perfect! It's funny... Wrap was one of the things I tried, but when I did I used it incorrectly. Glad to know how to use it now - and that it exists for both Math and Vector Math nodes. $\endgroup$
    – Mentalist
    Jun 8 at 7:39
3
$\begingroup$

Vector Math -> Modulo with divisor values of 1.0 should give you what you want.

enter image description here

You can Separate XYZ into whatever axis you want, or manipulate further with Mapping.

$\endgroup$
1
  • 4
    $\begingroup$ Note that modulo gives negative values for negative inputs. It's not really clear what the behaviour should be though, as can be seen here for instance torstencurdt.com/tech/posts/modulo-of-negative-numbers so the devs chose to restrict to [-num;num] instead of [0:num] $\endgroup$
    – Gorgious
    Jun 8 at 7:34

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.