patriciogonzalezvivo / thebookofshaders

Step-by-step guide through the abstract and complex universe of Fragment Shaders.
http://TheBookOfShaders.com
Other
6.08k stars 690 forks source link

Chapter 05 non-standard use of smoothstep #418

Open alextenb opened 8 months ago

alextenb commented 8 months ago

Hi, the first code example in Chapter 05 contains a usage of smoothstep which should produce undefined output according to the OpenGL docs.

// Plot a line on Y using a value between 0.0-1.0
float plot(vec2 st) {    
    return smoothstep(0.02, 0.0, abs(st.y - st.x));
}

It looks like, on my hardware, the result ends up being identical to:

float plot(vec2 st) {    
    return 1.0 - smoothstep(0.0, 0.02, abs(st.y - st.x));
}

But according to the OpenGL docs (and the documentation for the smoothstep function contained in the Book of Shaders) this function requires edge1 to be strictly greater than edge0. Being new to shaders, this confused me and I had to mess around with it to figure out what was actually happening.