math.smoothstep and math.smootherstep return a hard step when min is greater than max
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from playcanvas/engine
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
playcanvas/engine#9769 ·
Maintainers usually reply within 1 day
-
XrInputSource#elementEntity holds the ElementComponent, not the Entity its docs and type promiseOpenarea: xr
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
playcanvas/engine#9660 ·
Maintainers usually reply within 1 day
-
Isotropic GGX specular visibility term uses alpha^4 instead of alpha^2Possibly taken @Yahiro025 claimed this 23 days ago. Openarea: gltf area: graphics
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
playcanvas/engine#9510 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
playcanvas/engine#9335 ·
Maintainers usually reply within 1 day
-
area: ui enhancement
Difficulty 1/5 Under an hour Newbie friendliness 72/100
playcanvas/engine#5777 ·
Maintainers usually reply within 1 day
All issues in playcanvas/engine
Similar issues
-
BUG
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 75/100
flarum/framework#5231 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/rocketmq-dashboard#6896 ·
Maintainers usually reply within 3 days
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[workshop-sync] workshop/side-quest-17-06-output-injection.md: stale add_comment.cjs line referencesOpendocumentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
githubnext/gh-aw-workshop#4679 ·
Maintainers usually reply within 1 day