I was working through https://thebookofshaders.com/05/ when I came across some unintuitive behaviour of smoothstep
. I wanted to understand it better so I replaced the following line of code:
return smoothstep(0.02, 0.0, abs(st.y - st.x));
With all arguments as float literals:
return smoothstep(0.02, 0.0, 0.0);
I was expecting smoothstep
to return 1.0 but instead it seems to always return 0.0 regardless of the value of the third argument. If instead of that you use a float variable:
float temp = 0.0;
return smoothstep(0.02, 0.0, temp);
It works as expected and returns 1.0. Why is this? I assume this is documented somewhere though it's not obvious what to search for.
Minimal, Reproducible Example:
#ifdef GL_ES
precision mediump float;
#endif
void main() {
float diff = 0.0;
float green = smoothstep(0.2, 0.0, diff);
// Won't result in green if uncommented
// green = smoothstep(0.2, 0.0, 0.0);
gl_FragColor = vec4(0.0, green, 0.0, 1.0);
}
```