patriciogonzalezvivo / thebookofshaders

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

Mistake in smoothstep description: "undefined if edge0 ≥ edge1" #363

Open singalen opened 2 years ago

singalen commented 2 years ago

https://thebookofshaders.com/glossary/?search=smoothstep says "Results are undefined if edge0 ≥ edge1".

At the same time, https://thebookofshaders.com/05/ uses smoothstep(0.02, 0.0, ...).

NVidia reference says:

which actually explains why and how the code works.

mogita commented 1 year ago

It'd be helpful to add a note after the definition about how GLSL actually implements smoothstep in a way that reverse the output to [1, 0] when the left side is greater than the right side. I looked at the code and tried to understand how it actually worked but apparently not complying with what the definition said.

stonerfish commented 1 year ago

The GLSL spec does say "Results are undefined if edge0 >= edge1." The lesson learned in this section is the specs do not define what is actually implemented. It took me a bit for that to sink in.