## cubic (`lygia`/`math`/`cubic`)

cubic polynomial https://iquilezles.org/articles/smoothsteps/

Use:

``````<float|vec2|vec3|vec4> cubic(<float|vec2|vec3|vec4> value[, <float> in, <float> out]);
``````

Check it on Github

``````
#ifndef FNC_CUBIC
#define FNC_CUBIC
float cubic(const in float v) { return v*v*(3.0-2.0*v); }
vec2  cubic(const in vec2 v)  { return v*v*(3.0-2.0*v); }
vec3  cubic(const in vec3 v)  { return v*v*(3.0-2.0*v); }
vec4  cubic(const in vec4 v)  { return v*v*(3.0-2.0*v); }

float cubic(const in float v, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
float v2 = v * v;
float v3 = v * v2;
return a * v3 + b * v2 + c * v;
}

vec2 cubic(const in vec2 v, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
vec2 v2 = v * v;
vec2 v3 = v * v2;
return a * v3 + b * v2 + c * v;
}

vec3 cubic(const in vec3 v, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
vec3 v2 = v * v;
vec3 v3 = v * v2;
return a * v3 + b * v2 + c * v;
}

vec4 cubic(const in vec4 v, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
vec4 v2 = v * v;
vec4 v3 = v * v2;
return a * v3 + b * v2 + c * v;
}
#endif
``````

Use:

``````<float|float2|float3|float4> cubic(<float|float2|float3|float4> value [, <float> in, <float> out]);
``````

Check it on Github

``````
#ifndef FNC_CUBIC
#define FNC_CUBIC
float   cubic(const in float v)   { return v*v*(3.0-2.0*v); }
float2  cubic(const in float2 v)  { return v*v*(3.0-2.0*v); }
float3  cubic(const in float3 v)  { return v*v*(3.0-2.0*v); }
float4  cubic(const in float4 v)  { return v*v*(3.0-2.0*v); }

float cubic(const in float value, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
float value2 = value * value;
float value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

float2 cubic(const in float2 value, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
float2 value2 = value * value;
float2 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

float3 cubic(const in float3 value, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
float3 value2 = value * value;
float3 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

float4 cubic(const in float4 value, in float slope0, in float slope1) {
float a = slope0 + slope1 - 2.;
float b = -2. * slope0 - slope1 + 3.;
float c = slope0;
float4 value2 = value * value;
float4 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}
#endif
``````

Check it on Github

``````
fn cubic(v: f32) -> f32 { return v*v*(3.0-2.0*v); }
fn cubic2(v: vec2f) -> vec2f { return v*v*(3.0-2.0*v); }
fn cubic3(v: vec3f) -> vec3f { return v*v*(3.0-2.0*v); }
fn cubic4(v: vec4f) -> vec4f { return v*v*(3.0-2.0*v); }
``````

Dependencies:

Use:

``````<float|float2|float3|float4> cubic(<float|float2|float3|float4> value [, <float> in, <float> out]);
``````

Check it on Github

``````

#ifndef FNC_CUBIC
#define FNC_CUBIC
inline __host__ __device__ float   cubic(float v)   { return v * v * (3.0f - 2.0f * v); }
inline __host__ __device__ float2  cubic(float2 v)  { return v * v * (3.0f - 2.0f * v); }
inline __host__ __device__ float3  cubic(float3 v)  { return v * v * (3.0f - 2.0f * v); }
inline __host__ __device__ float4  cubic(float4 v)  { return v * v * (3.0f - 2.0f * v); }

inline __host__ __device__ float cubic(float value, float slope0, float slope1) {
float a = slope0 + slope1 - 2.0f;
float b = -2.0f * slope0 - slope1 + 3.0f;
float c = slope0;
float value2 = value * value;
float value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

inline __host__ __device__ float2 cubic(float2 value, float slope0, float slope1) {
float a = slope0 + slope1 - 2.0f;
float b = -2.0f * slope0 - slope1 + 3.0f;
float c = slope0;
float2 value2 = value * value;
float2 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

inline __host__ __device__ float3 cubic(float3 value, float slope0, float slope1) {
float a = slope0 + slope1 - 2.0f;
float b = -2.0f * slope0 - slope1 + 3.0f;
float c = slope0;
float3 value2 = value * value;
float3 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}

inline __host__ __device__ float4 cubic(float4 value, float slope0, float slope1) {
float a = slope0 + slope1 - 2.0f;
float b = -2.0f * slope0 - slope1 + 3.0f;
float c = slope0;
float4 value2 = value * value;
float4 value3 = value * value2;
return a * value3 + b * value2 + c * value;
}
#endif
``````