Fixed SIMD smoothstep

This commit is contained in:
Christophe 2024-02-08 21:46:37 +01:00
parent 90f2b025b1
commit 9356f40830
2 changed files with 21 additions and 8 deletions

View File

@ -102,17 +102,23 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_reflect(glm_vec4 I, glm_vec4 N)
GLM_FUNC_QUALIFIER __m128 glm_vec4_refract(glm_vec4 I, glm_vec4 N, glm_vec4 eta)
{
glm_vec4 const dot0 = glm_vec4_dot(N, I);
glm_vec4 const mul0 = _mm_mul_ps(eta, eta);
glm_vec4 const mul1 = _mm_mul_ps(dot0, dot0);
glm_vec4 const sub0 = _mm_sub_ps(_mm_set1_ps(1.0f), mul0);
glm_vec4 const sub1 = _mm_sub_ps(_mm_set1_ps(1.0f), mul1);
glm_vec4 const mul2 = _mm_mul_ps(sub0, sub1);
// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
// if (k < 0.0)
// R = genType(0.0); // or genDType(0.0)
// else
// R = eta * I - (eta * dot(N, I) + sqrt(k)) * N;
if(_mm_movemask_ps(_mm_cmplt_ss(mul2, _mm_set1_ps(0.0f))) == 0)
glm_vec4 const dot0 = glm_vec4_dot(N, I); // dot(N, I)
glm_vec4 const mul0 = _mm_mul_ps(eta, eta); // eta * eta
glm_vec4 const mul1 = _mm_mul_ps(dot0, dot0); // dot(N, I) * dot(N, I)
glm_vec4 const sub1 = _mm_sub_ps(_mm_set1_ps(1.0f), mul1); // (1.0 - dot(N, I) * dot(N, I))
glm_vec4 const mul2 = _mm_mul_ps(mul0, sub1); // eta * eta * (1.0 - dot(N, I) * dot(N, I))
glm_vec4 const sub0 = _mm_sub_ps(_mm_set1_ps(1.0f), mul2); // 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
if(_mm_movemask_ps(_mm_cmplt_ss(sub0, _mm_set1_ps(0.0f))) == 0)
return _mm_set1_ps(0.0f);
glm_vec4 const sqt0 = _mm_sqrt_ps(mul2);
glm_vec4 const sqt0 = _mm_sqrt_ps(sub0);
glm_vec4 const mad0 = glm_vec4_fma(eta, dot0, sqt0);
glm_vec4 const mul4 = _mm_mul_ps(mad0, N);
glm_vec4 const mul5 = _mm_mul_ps(eta, I);

View File

@ -181,6 +181,13 @@ namespace refract
Error += glm::all(glm::equal(C, glm::dvec2(0.0, -1.0), 0.0001)) ? 0 : 1;
}
{
glm::vec4 A(0.0f, -1.0f, 0.0f, 0.0f);
glm::vec4 B(0.0f, 1.0f, 0.0f, 0.0f);
glm::vec4 C = glm::refract(A, B, 0.5f);
Error += glm::all(glm::equal(C, glm::vec4(0.0, -1.0, 0.0f, 0.0f), 0.0001f)) ? 0 : 1;
}
return Error;
}
}//namespace refract