thebookofshaders
thebookofshaders copied to clipboard
Shaping functions: first example uses undefined behavior of smoothstep()
The first code example in the Shaping functions chapter has the following plot function:
float plot(vec2 st) {
return smoothstep(0.02, 0.0, abs(st.y - st.x));
}
Clicking on smoothstep() takes you to the glossary which states:
float smoothstep(float edge0, float edge1, float x) ... Results are undefined if edge0 ≥ edge1.
Note the first argument (0.02) is greater the second (0.0), which appears to be undefined. All the Khronos API references I could find say the same. However, also note the example shader does render properly on my machine.
I agree the "twisted" parameters should be explained in the book, the docs make it look like it's against the rules. However it's frequently used, seems like an inversion, similar to 1.0 - smoothstep(0.0, 0.02 ...)
. (Example)