From 1ac95994c437cb9e544ebc9e91adc2916c7601c7 Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 8 Feb 2024 21:46:37 +0100 Subject: [PATCH] Fixed SIMD smoothstep --- glm/simd/geometric.h | 22 ++++++++++++++-------- test/core/core_func_geometric.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/glm/simd/geometric.h b/glm/simd/geometric.h index 07d7cbcc..afbe590e 100644 --- a/glm/simd/geometric.h +++ b/glm/simd/geometric.h @@ -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); diff --git a/test/core/core_func_geometric.cpp b/test/core/core_func_geometric.cpp index 2820ad4c..86add55e 100644 --- a/test/core/core_func_geometric.cpp +++ b/test/core/core_func_geometric.cpp @@ -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