Last active
April 11, 2021 16:42
-
-
Save YuryScript/180616db38ace9e22739b88edf8420d1 to your computer and use it in GitHub Desktop.
[JS] Smoothstep function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function smoothstep(edgeA, edgeB, x) { | |
| // Scale, bias and saturate x to 0..1 range | |
| x = clamp((x - edgeA) / (edgeB - edgeA), 0, 1); | |
| // Evaluate polynomial | |
| return x * x * (3 - 2 * x); | |
| } | |
| function clamp(x, min, max) { | |
| if (x < min) | |
| return min | |
| if (x > max) | |
| return max | |
| return x | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment