2
$\begingroup$

enter image description here

I have this color ramp set to ease. Is there a way to recreate it with math nodes? I want to be able to input custom textures and use a node group with it. The solutions I've found don't work for ease.

$\endgroup$
9
  • $\begingroup$ What do you mean, recreate it with math nodes? There’s nowhere math nodes can go that this can’t. Ease is just an interpolation type and doesn’t change that. What are you trying to do with custom textures and node groups? $\endgroup$
    – TheLabCat
    Commented 12 hours ago
  • $\begingroup$ Instead of using colors in the color stops, I want to use image textures, and I want to recreate this color ramp as a set of math nodes to achieve that. Also because color ramps don't work with node groups $\endgroup$ Commented 12 hours ago
  • 1
    $\begingroup$ What are color stops? Do you want the math nodes to produce color? How can "image textures" fit this in any way? Of course color ramps work with node groups. $\endgroup$ Commented 11 hours ago
  • 1
    $\begingroup$ @DanielMöller "What are color stops?" Honestly? Color stops are those sliders which you can place on the Color Ramp to assign a color to a specific Fac value between 0 and 1. See: Blender Manual: Color Ramp Widget. What is so hard to understand in this question? There are solutions out there where people reproduce Color Ramp behaviour for example with Map Range or Mix Color nodes. And instead of using plain colors one could plug image textures into A and B. $\endgroup$ Commented 9 hours ago
  • 1
    $\begingroup$ Fair question, IMHO. The most obvious way to go about this is to read the source code for color ramp, but I see Gordon figured the logic by experimentation (which is often easier than reading source because of poor code quality xD). $\endgroup$ Commented 4 hours ago

2 Answers 2

4
$\begingroup$

There is a way recreating this with Map Range nodes set to Smooth Step interpolation, this seems to be the same as Ease interpolation in a Color Ramp.

This is a material with a standard Color Ramp set to Ease interpolation and four color stops:

  1. blue at 0.1
  2. green at 0.5
  3. orange at 0.8
  4. pink at 1.0

standard color ramp

The following comparison now shows a strip with the Color Ramp material on top, in the middle a recreation with Map Range nodes (material nodetree further below) and at the bottom a material using a Color Ramp with Linear extrapolation to demonstrate that the first two indeed have a different interpolation:

different materials

As you can see, the first two look the same, which is different from the default Linear interpolation at the bottom. To achieve the same result as the Color Ramp using Map Range nodes, you need $n-1$ Map Range and $n-1$ Mix Color nodes if you have $n$ stops in the Color Ramp.

The first Map Range node gets the position of the first stop as From Min value and the position of the second stop as From Max value. The To Min and To Max values have to be 0 and 1 for all Map Range nodes and they all have to be set to Smooth Step interpolation.

The result is used as factor in a Mix Color node, with A being the color at the first stop, and B the color of the second stop.

In the second Map Range node the From Min is the position of the second stop, From Max the position of the third stop. The result goes into a second Mix Color node with A being the output of the first Mix Color node and B is the color at the third stop.

And everything one more time, now Map Range 3 has the third stop position as From Min, the fourth stop position as From Max, the Mix Color has the second mix output in A and the fourth color in B:

map range material

But if you want to change the stop positions and do not want to do it separately on each Map Range node, you could use separate Value nodes to feed them into the respective From Min and From Max sockets:

map range with separate values

Now I know the following looks a bit messy, but the good thing about the solution with the Map Range and Mix Color is - as you probably already realized - you can plug textures in there instead of just plain colors, I have simply used some procedural textures here:

textures

By the way just another comparison: you said you found solutions but they "don't work for ease". In the image below you have my textures version, now one with the Ease interpolation, the other with Linear interpolation. Yes, there is a difference, but depending on the textures I do not think it is necessary to explicitly use Ease here:

textures ease vs linear

$\endgroup$
1
$\begingroup$

If you want to use a texture (or a field in geonodes) to control positions of stops, you will have to use Gordon's answer, however if you just want to replace solid colors with textures, you just need to replace colors. Well those colors have to be unique but that's it. So set the stop values to $0, 1, 2, 3...$ and then the floor is 1st texture, the ceil is 2nd texture and the fraction is the factor of mixing between the two:

Imgur mirror (SE image hosting has problems)

The setup is very easy:

  1. Color Ramp has stops with values $0, 1, 2...$. You could repeat the values (so that there's an area where the texture isn't mixed with another), go back to lower values, you could set the stops to non-integer values... But this is an example in the simplest form. You should be able to choose any interpolation mode you wish.
  2. The color from color ramp goes to Fraction, Floor, Ceil.
  3. For each texture, you compare a value associated in that texture (vertically I start with 0 and increase by 1 for each next texture below) with the floored value, and with the ceiled value.
  4. Vector Math: Scale - The texture data is multiplied by 0 if comparison fails (becomes black) or by 1 if comparison succeeds (no change).
  5. Finally all checked textures are added together - adding a black texture is a no-op so this is just a way to propagate the winner of the checks.
  6. And finally use the fraction to interpolate between the two winners - the texture associated with left stop and the texture associated with right stop.

Imgur mirror

v.4.4.0.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.