Skip to content

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

Open
zzoraemon043 wants to merge 1 commit into
playcanvas:mainfrom
zzoraemon043:fix/smoothstep-reversed-edges
Open

zzoraemon043 wants to merge 1 commit into
playcanvas:mainfrom
zzoraemon043:fix/smoothstep-reversed-edges

Conversation

@zzoraemon043

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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

1 participant