-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added smoothstep built-in function #27231
Conversation
ee23fa5
to
7b15e52
Compare
Lerp is a contraction for |
Renamed to smooth_step |
Added C# version too |
5f0418c
to
f9641b5
Compare
How does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# change looks good to me but is wrongly formatted.
@Calinou explain more please ? I think its different functions, even if you somehow force the results to be equal its not as easy as single call |
@Calinou Tested with KmPlot, the closest ease + lerp combination should be: lerp(a, b, ease(t, -1.6521)) Here are some plots of both, along with their derivatives. Notice that ease's derivative has a discontinuity at x=0.5, unlike smoothstep's derivative.
|
1f9c591
to
18491cc
Compare
Added is_equal_approx check to avoid division by zero |
nice addition, I wonder whether it should be "smooth_step" or "smoothstep" like in glsl.. |
Changed to smoothstep (as also suggested by Calinou in IRC) |
ca5ddd2
to
87d5009
Compare
f83cf5d
to
78ee9a6
Compare
@@ -101,6 +101,7 @@ class VisualScriptBuiltinFunc : public VisualScriptNode { | |||
VAR_TO_BYTES, | |||
BYTES_TO_VAR, | |||
COLORN, | |||
MATH_SMOOTHSTEP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a problem if it's included further up before MATH_DECTIME
, as for core/math
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by @vnen
I believe this breaks compatibility if put here: it should be put at the end of the list. You can see in the doc changes that all constants got new values, so if someone is using a function from below, suddenly the functions will be changed and it'll break the code.
e3ffe18
to
078401b
Compare
Thanks! |
Cherry-picked for 3.1.1. |
<argument index="2" name="weight" type="float"> | ||
</argument> | ||
<description> | ||
Returns a number smoothly interpolated between the [code]from[/code] and [code]to[/code], based on the [code]weight[/code]. Similar to [method lerp], but interpolates faster at the beginning and slower at the end. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Chaosus, actually this implementation of smoothstep is similar to inverse_lerp and not to lerp so this description is misleading. Also another difference (besides interpolating faster at the beginning and slower at the end) is that smoothstep clamps result to range <0, 1>. So this description probably needs an update.
(no idea if that's proper place for this note)
Personally I misses hermite interpolation. So many algorithms are depends on it. It should be in the core, cuz its common in video game programming. Unity also have it in the builtin Math class https://docs.unity3d.com/ScriptReference/Mathf.SmoothStep.html
In Godot, currently it can be only used in shaders(smoothstep) or in Tween's. This PR exposes it to core -
I named it smooth_lerp for easy search it within other lerp-functions and(I suppose) its just another type of linear interpolation.I will add C# version later, (if this will be accepted)