Skip to content

Fix math.smoothstep and smootherstep when min is greater than max - #9798

Merged
mvaligursky merged 1 commit into
playcanvas:mainfrom
zzoraemon043:fix/smoothstep-reversed-edges
Oct 26, 2026
Merged

mvaligursky merged 1 commit into
playcanvas:mainfrom
zzoraemon043:fix/smoothstep-reversed-edges

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Description

math.smoothstep and math.smootherstep returned early on x <= min / x >= max, which only works when min < max. With reversed edges they became an inverted hard step at min. They now clamp the normalized value to [0, 1] before the polynomial, the same as GLSL, so reversed edges give a falling ramp. When min === max the result stays a step (0 at or below, 1 above), as before, instead of dividing by zero. The min / max docs now say which value maps to 0 and 1.

Added tests for clamping, reversed edges (including the values from the issue) and equal edges.

Fixes #9767

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

@mvaligursky

Copy link
Copy Markdown
Contributor

Thanks, just the fix I hoped for.

@mvaligursky
mvaligursky merged commit 92115e7 into playcanvas:main Oct 26, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

math.smoothstep and math.smootherstep return a hard step when min is greater than max

2 participants