OpenShadingLanguage
OpenShadingLanguage copied to clipboard
docs: Fix specification clarity 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);
}