diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2019-04-08 10:03:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-08 10:03:42 +0200 |
| commit | d211aff777ec338a5f57cece1c7bf76120d0622d (patch) | |
| tree | c7d6a922eb7e7a5dd3995c366848f39c82338220 /core/math/math_funcs.h | |
| parent | 5a64c679cfc5463afd4a703b1c6e437d894b22b1 (diff) | |
| parent | 514a3fb96a6ad97eb9488cacba7143566cb17d27 (diff) | |
| download | redot-engine-d211aff777ec338a5f57cece1c7bf76120d0622d.tar.gz | |
Merge pull request #27231 from Chaosus/smoothstep
Added smoothstep built-in function
Diffstat (limited to 'core/math/math_funcs.h')
| -rw-r--r-- | core/math/math_funcs.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 6ac6839827..0d209402dd 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -208,6 +208,17 @@ public: static _ALWAYS_INLINE_ double range_lerp(double p_value, double p_istart, double p_istop, double p_ostart, double p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); } static _ALWAYS_INLINE_ float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); } + static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_weight) { + if (is_equal_approx(p_from, p_to)) return p_from; + double x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0, 1.0); + return x * x * (3.0 - 2.0 * x); + } + static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_weight) { + if (is_equal_approx(p_from, p_to)) return p_from; + float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f); + return x * x * (3.0f - 2.0f * x); + } + static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; } static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; } |
