Skip to content

Instantly share code, notes, and snippets.

@YuryScript
Created April 11, 2021 16:44
Show Gist options
  • Select an option

  • Save YuryScript/0dd2b49e1f0cccf41fc0502142048b47 to your computer and use it in GitHub Desktop.

Select an option

Save YuryScript/0dd2b49e1f0cccf41fc0502142048b47 to your computer and use it in GitHub Desktop.
[JS] Smootherstep function
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