Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#9,767 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
game-dev

Research direction

The early returns that cause the hard step are in src/core/math/math.js, in the smoothstep and smootherstep functions, around lines 263-270 and 285-292. Read those guards next to the interpolation below them to see why reversed edges never reach the ramp. Done means the three example calls in the table return the falling-ramp values, and the existing math tests still pass.

Written by the indexing model from the issue text.

Description

math.smoothstep(min, max, x) and math.smootherstep(min, max, x) return early when x <= min or x >= max, before they interpolate:

https://github.com/playcanvas/engine/blob/bf6b6e7efe5faefd5dcf789ef7250e2be002a96b/src/core/math/math.js#L263-L270
https://github.com/playcanvas/engine/blob/bf6b6e7efe5faefd5dcf789ef7250e2be002a96b/src/core/math/math.js#L285-L292

With min greater than max - a falling ramp - every x <= min returns 0 and every x > min returns 1. The result is an inverted hard step at min, not a ramp:

call returns a falling ramp would give
math.smoothstep(-0.3, -0.6, -0.2) 1 0
math.smoothstep(-0.3, -0.6, -0.45) 0 0.5
math.smoothstep(-0.3, -0.6, -0.7) 0 1

Reversed edges are a common idiom in shader code, where smoothstep(edge0, edge1, x) with edge0 > edge1 usually evaluates to the falling ramp, so the same expression moved between a shader and JavaScript changes meaning without any sign. Debug builds give no warning, and the docs describe the arguments as the lower and upper bound without saying what happens when they are the other way round.

Hit twice while building a game example: a terrain height falloff became a 110 m vertical drop within one grid quad, and a lighting fade became an on / off switch.

Dominant language
JavaScript
Stars
17k
Forks
2k
Avg merge
3h 59m
Merged PRs (30d)
322

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from playcanvas/engine

All issues in playcanvas/engine

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.