1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

This PR handles the smoothstep degenerate case where the range is empty.

It also updates the documentation to describe positive and negative ranges.

Co-Authored-By: Hugo Locurcio <hugo.locurcio@hugo.pro>
Co-Authored-By: kleonc <9283098+kleonc@users.noreply.github.com>
This commit is contained in:
Malcolm Nixon
2024-06-14 03:08:16 -04:00
parent ee363af0ed
commit 23fc704cbc
2 changed files with 14 additions and 4 deletions

View File

@@ -447,14 +447,22 @@ public:
static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_s) {
if (is_equal_approx(p_from, p_to)) {
return p_from;
if (likely(p_from <= p_to)) {
return p_s <= p_from ? 0.0 : 1.0;
} else {
return p_s <= p_to ? 1.0 : 0.0;
}
}
double s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0, 1.0);
return s * s * (3.0 - 2.0 * s);
}
static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_s) {
if (is_equal_approx(p_from, p_to)) {
return p_from;
if (likely(p_from <= p_to)) {
return p_s <= p_from ? 0.0f : 1.0f;
} else {
return p_s <= p_to ? 1.0f : 0.0f;
}
}
float s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0f, 1.0f);
return s * s * (3.0f - 2.0f * s);