Skip to content
New issue

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

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

Already on GitHub? # to your account

Shaping functions: first example uses undefined behavior of smoothstep() #344

Open
kevinms opened this issue May 5, 2021 · 1 comment
Open

Comments

@kevinms
Copy link

kevinms commented May 5, 2021

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.

@timohausmann
Copy link
Contributor

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)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants