Skip to content

Instantly share code, notes, and snippets.

@YuryScript
Last active April 11, 2021 16:42
Show Gist options
  • Select an option

  • Save YuryScript/180616db38ace9e22739b88edf8420d1 to your computer and use it in GitHub Desktop.

Select an option

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