# What is the math for the B-spline interpolation of a color ramp with two color stops?

I often use a color ramp with only two color stops as a way to modify the output of a texture parameter as in this example.

I would like to be able to do something similar in a node group where the positions of the two color stops are input parameters. Such a group might look like this

There is a solution for a linear color ramp in this answer.

A similar solution would work for the other interpolation types, provided I knew the interpolation equation.

What is the equation for b-spline?

• Hi Marty. Does it need to specifically be B-Spline or would something more akin to Ease be useful? (I don’t know the maths for b-spline but a generic ‘ease’ should be feasible without much difficulty) Sep 10, 2018 at 15:39
• Hi Rich. Ease would definitely be useful. Sep 10, 2018 at 22:38

Implementing B-Spline is quite a bit beyond my maths capabilities but a simple 'ease' is certainly feasible. To achieve this you can calculate the 'influence' of each of the control points and combine these to produce the overall influence. Varying the parameters controls the shape of the curve.

I've created a Desmos example which can be accessed here : https://www.desmos.com/calculator/orfi1cybkc and is as shown in the following image :

Breaking this down a bit, we start with two points along the x-axis defined as p1 and p2 along with associated values v1 and v2 so each point is defined as (p,v). These can be adjusted and positioned as desired.

To determine the 'height' (y) at each point along the x-axis we need to determine the relative influence of each point. For this we first determine the distance as d = abs(x - p) for each 'point' (p1, p2).

The variables w and E (exponent) control the shape of the curve. w is present to avoid divide by zero errors by ensuring there is always a small offset from zero, while E controls how the influence of each point drops off over distance. Each influence is determined with :

i = 1 / (w + pow(d,E))


Once we have the 'influence' of each point (i1, i2) we can combine them with :

y = (v1*i1 + v2*i2) / (i1 + i2)


To build the nodes I opted to use the Dynamic Maths Expression add-on developed for this answer which can be downloaded from here. The add-on allows you to simply type an equation and the corresponding nodes are automatically built within a node group hidden behind the node. This allows complicated expressions to be very easily constructed.

For instance, for the 'influence' calculation I used the following equation :

Influence=1/(w+Distance**Exponent)


This produces the following node :

Within the node are the following generated nodes to implement the specified expression :

Similar can be done with 'Distance' and 'Output' as shown in the following (all wrapped within a Group for convenience) :

This node group can now be used to produce the required 'easing' curve as demonstrated with this example :

Using an exponent of 1.0 will produce a straight line :

Exponents greater than 1.0 will produce increasing curve :

1.5

2.5

4.0

Exponents less than 1.0 will produce the opposite curve :

0.5

Two blend files are included - one that requires the Dynamic Expression add-on and one that does not require the Dynamic Expression add-on (the 'internal' node groups have been transferred into standard node groups) :

Output=((1/(0.001+abs(x-Point1)**Exponent))*Value1+(1/(0.001+abs(x-Point2)**Exponent))*Value2)/((1/(0.001+abs(x-Point1)**Exponent))+(1/(0.001+abs(x-Point2)**Exponent)))
The text passage contains a mathematical question about the equation for B-spline interpolation of a color ramp with two color stops, and it also provides a solution for a simpler 'ease' function as an alternative.
single_question_with_answer
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
# What is the math for the B-spline interpolation of a color ramp with two color stops?

I often use a color ramp with only two color stops as a way to modify the output of a texture parameter as in this example.

I would like to be able to do something similar in a node group where the positions of the two color stops are input parameters. Such a group might look like this

There is a solution for a linear color ramp in this answer.

A similar solution would work for the other interpolation types, provided I knew the interpolation equation.

What is the equation for b-spline?

• Hi Marty. Does it need to specifically be B-Spline or would something more akin to Ease be useful? (I don’t know the maths for b-spline but a generic ‘ease’ should be feasible without much difficulty) Sep 10, 2018 at 15:39
• Hi Rich. Ease would definitely be useful. Sep 10, 2018 at 22:38

Implementing B-Spline is quite a bit beyond my maths capabilities but a simple 'ease' is certainly feasible. To achieve this you can calculate the 'influence' of each of the control points and combine these to produce the overall influence. Varying the parameters controls the shape of the curve.

I've created a Desmos example which can be accessed here : https://www.desmos.com/calculator/orfi1cybkc and is as shown in the following image :

Breaking this down a bit, we start with two points along the x-axis defined as p1 and p2 along with associated values v1 and v2 so each point is defined as (p,v). These can be adjusted and positioned as desired.

To determine the 'height' (y) at each point along the x-axis we need to determine the relative influence of each point. For this we first determine the distance as d = abs(x - p) for each 'point' (p1, p2).

The variables w and E (exponent) control the shape of the curve. w is present to avoid divide by zero errors by ensuring there is always a small offset from zero, while E controls how the influence of each point drops off over distance. Each influence is determined with :

i = 1 / (w + pow(d,E))


Once we have the 'influence' of each point (i1, i2) we can combine them with :

y = (v1*i1 + v2*i2) / (i1 + i2)


To build the nodes I opted to use the Dynamic Maths Expression add-on developed for this answer which can be downloaded from here. The add-on allows you to simply type an equation and the corresponding nodes are automatically built within a node group hidden behind the node. This allows complicated expressions to be very easily constructed.

For instance, for the 'influence' calculation I used the following equation :

Influence=1/(w+Distance**Exponent)


This produces the following node :

Within the node are the following generated nodes to implement the specified expression :

Similar can be done with 'Distance' and 'Output' as shown in the following (all wrapped within a Group for convenience) :

This node group can now be used to produce the required 'easing' curve as demonstrated with this example :

Using an exponent of 1.0 will produce a straight line :

Exponents greater than 1.0 will produce increasing curve :

1.5

2.5

4.0

Exponents less than 1.0 will produce the opposite curve :

0.5

Two blend files are included - one that requires the Dynamic Expression add-on and one that does not require the Dynamic Expression add-on (the 'internal' node groups have been transferred into standard node groups) :

Output=((1/(0.001+abs(x-Point1)**Exponent))*Value1+(1/(0.001+abs(x-Point2)**Exponent))*Value2)/((1/(0.001+abs(x-Point1)**Exponent))+(1/(0.001+abs(x-Point2)**Exponent)))
user
The text passage contains a mathematical question about the equation for B-spline interpolation of a color ramp with two color stops, and it also provides a solution for a simpler 'ease' function as an alternative.

TYPE: SINGLE_QUESTION_WITH_ANSWER