g-truc / glm

OpenGL Mathematics (GLM)
https://glm.g-truc.net
Other
9.1k stars 2.12k forks source link

glm_vec4_smoothstep #1222

Closed gottfriedleibniz closed 7 months ago

gottfriedleibniz commented 7 months ago

glm_vec4_smoothstep incorrectly computes 't'. Per GLSL:

genFType t;
t = clamp ((x - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);

Stepping through the function

glm_vec4 const sub0 = glm_vec4_sub(x, edge0);      // (x - edge0)
glm_vec4 const sub1 = glm_vec4_sub(edge1, edge0);  // (edge1 - edge0)
glm_vec4 const div0 = glm_vec4_sub(sub0, sub1);    // (x - edge0) - (edge1 - edge0); should be divide
glm_vec4 const clp0 = glm_vec4_clamp(div0, _mm_setzero_ps(), _mm_set1_ps(1.0f));
/// ...