Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Fix specification clarity of smoothstep #1851

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Aug 21, 2024

  1. docs: Fix specification clarity and behavior of smoothstep

    Swap the confusing edge0/edge1 nomenclature of the smoothstep
    declaration to the more intuitive low/high.
    
    It was pointed out on Slack by Arnon Marcus that the spec's
    description of smoothstep was ambiguous about the behavior when
    low==high: does it return 0 or 1 if x is the same value? The
    documentation is unclear.
    
    The implementation returned 1, which I think is the "correct" behavior
    in the sense that it matches the results of step() function with that
    edge. So update the documentation to match.
    
    Also Arnon pointed out that things are especially weird if low > high,
    it's non-monotonic.  This seems to be fixed by simply reversing the
    relative order of the `if x <= low` and `if x >= high` tests:
    basically, it also makes it match step(x, high) and be monotonic.
    
    This is a cleaner formal definition of what smoothstep should do,
    namely:
    
        if (x >= high) {
            return 1.0f;
        } else if (x <= low) {
            return 0.0f;
        } else {
            float t = (x - low) / (high - low);
            return (3.0f-2.0f*t)*(t*t);
        }
    
    Signed-off-by: Larry Gritz <[email protected]>
    lgritz committed Aug 21, 2024
    Configuration menu
    Copy the full SHA
    67e886e View commit details
    Browse the repository at this point in the history