mirror of
https://github.com/g-truc/glm.git
synced 2024-11-14 14:04:36 +00:00
Fixed SIMD smoothstep
This commit is contained in:
parent
b101e8f3de
commit
1ac95994c4
@ -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_FUNC_QUALIFIER __m128 glm_vec4_refract(glm_vec4 I, glm_vec4 N, glm_vec4 eta)
|
||||||
{
|
{
|
||||||
glm_vec4 const dot0 = glm_vec4_dot(N, I);
|
// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I));
|
||||||
glm_vec4 const mul0 = _mm_mul_ps(eta, eta);
|
// if (k < 0.0)
|
||||||
glm_vec4 const mul1 = _mm_mul_ps(dot0, dot0);
|
// R = genType(0.0); // or genDType(0.0)
|
||||||
glm_vec4 const sub0 = _mm_sub_ps(_mm_set1_ps(1.0f), mul0);
|
// else
|
||||||
glm_vec4 const sub1 = _mm_sub_ps(_mm_set1_ps(1.0f), mul1);
|
// R = eta * I - (eta * dot(N, I) + sqrt(k)) * N;
|
||||||
glm_vec4 const mul2 = _mm_mul_ps(sub0, sub1);
|
|
||||||
|
|
||||||
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);
|
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 mad0 = glm_vec4_fma(eta, dot0, sqt0);
|
||||||
glm_vec4 const mul4 = _mm_mul_ps(mad0, N);
|
glm_vec4 const mul4 = _mm_mul_ps(mad0, N);
|
||||||
glm_vec4 const mul5 = _mm_mul_ps(eta, I);
|
glm_vec4 const mul5 = _mm_mul_ps(eta, I);
|
||||||
|
@ -181,6 +181,13 @@ namespace refract
|
|||||||
Error += glm::all(glm::equal(C, glm::dvec2(0.0, -1.0), 0.0001)) ? 0 : 1;
|
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;
|
return Error;
|
||||||
}
|
}
|
||||||
}//namespace refract
|
}//namespace refract
|
||||||
|
Loading…
Reference in New Issue
Block a user