I would like to know if there's a way to remap a value that goes from 0 to 1 constantly like this.

enter image description here

Into those values (those are examples).

enter image description here

This might be some function transformation but I can't find the way to do that. I've tried using a lookup texture but in my opinion this is not the best solution.
Thank you very much.


Okay so what you have is something like f(t)=(colour from gradient) as t goes from 0 to 1

This gives a nice smooth gradient, Where as if you take an auxiliary function, say a(t)=t^2 you'll notice this also goes between 0 and 1 (as t goes from 0 to 1 but it starts much slower then gets much faster.

You can compose the two, by using f(a(t)) this "alters the speed" that t changes if you will.

If f(t) has gradient 1 (uniformly, as the gradient increases at a constant rate, it must be 1 to go from the far ends of the colour gradient over a time of "1")

then f(a(t)) has gradient a'(t)f'(a(t)) which if a(t):=t^2 gives a rate of change of:
2t which at t=0.25 has gradient 0.5 (half the rate of change of the "normal" gradient) and at t=0.75 it has a gradient of 1.5 which is 50% faster than the usual one.

Using different a(t) you can get different effects

(someone else was asking about altering rates of change earlier, Can I use sin or cos for the non uniform rotation in unity 5? but for some reason I got a comment-less downvote, this is a similar question right?)


Take a function like:

f(t) = { 5t              if 0<= t < 0.1
       { 0.5+5(t-0.1)/9  if 0.1 <= t <= 1

This will have a shape like:

1                  1
|             ___/ |
|        ____/     |
|   ____/          |
|  /               |
| /                |
|/                 |
0                  1

It'll rise really sharply as we go from 0 to 0.1 then increase slowly to 1.

If we differentiate this we get:

f'(t) = { 5    if 0<= t < 0.1
        { 5/9  if 0.1 <= t <= 1

Which has a graph something like this:

|   _________

Notice the jump, it is NOT continuous, which will be apparent in the result.

Don't fret though, there are plenty of "smooth" functions to choose from!

  • \$\begingroup\$ Thank you for your very precise answer, I also found that the smoothstep function could help me do this. \$\endgroup\$
    – MaT
    Sep 25 '15 at 6:37

As @dari said, the smoothstep function is the best solution to achieve what I need.


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.