Created
April 11, 2021 16:44
-
-
Save YuryScript/0dd2b49e1f0cccf41fc0502142048b47 to your computer and use it in GitHub Desktop.
[JS] Smootherstep 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 smootherstep(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 * x * (x * (x * 6 - 15) + 10) | |
| } | |
| 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