Skip to content

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

Closed

Description

@mvaligursky

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

smoothstep(min, max, x) {
if (x <= min) return 0;
if (x >= max) return 1;
x = (x - min) / (max - min);
return x * x * (3 - 2 * x);
},

smootherstep(min, max, x) {
if (x <= min) return 0;
if (x >= max) return 1;
x = (x - min) / (max - min);
return x * x * x * (x * (x * 6 - 15) + 10);
},

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.

Activity

  1. added a commit that references this issue on Oct 26, 2026
    92115e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions