From aad5223da0b1d888e3b973bdc3b9d99c11b20d9b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 24 Mar 2024 06:31:29 +0300 Subject: [PATCH] change signature of refraction to let caller know if refraction occurs or not --- docs/source/vec2.rst | 18 +++++++++++------- docs/source/vec3.rst | 19 ++++++++++++------- docs/source/vec4.rst | 24 ++++++++++++++---------- include/cglm/call/vec2.h | 2 +- include/cglm/call/vec3.h | 2 +- include/cglm/call/vec4.h | 2 +- include/cglm/struct/vec2.h | 23 ++++++++++++----------- include/cglm/struct/vec3.h | 23 ++++++++++++----------- include/cglm/struct/vec4.h | 23 ++++++++++++----------- include/cglm/vec2.h | 18 +++++++++++------- include/cglm/vec3.h | 18 +++++++++++------- include/cglm/vec4.h | 18 +++++++++++------- src/vec2.c | 4 ++-- src/vec3.c | 4 ++-- src/vec4.c | 4 ++-- test/src/test_vec2.h | 13 +++++++++---- test/src/test_vec3.h | 13 +++++++++---- test/src/test_vec4.h | 9 +++++---- 18 files changed, 138 insertions(+), 99 deletions(-) diff --git a/docs/source/vec2.rst b/docs/source/vec2.rst index 8b1bdf02..95615d11 100644 --- a/docs/source/vec2.rst +++ b/docs/source/vec2.rst @@ -406,15 +406,19 @@ Functions documentation | *[in]* **N** *❗️ normalized ❗️* normal vector | *[out]* **dest** destination: reflection result -.. c:function:: void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) +.. c:function:: bool glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) - Refraction vector using entering ray, surface normal and refraction index - - If the angle between the entering ray I and the surface normal N is too - great for a given refraction index, the return value is zero + Computes refraction vector for an incident vector and a surface normal. + + Calculates the refraction vector based on Snell's law. If total internal reflection + occurs (angle too great given eta), dest is set to zero and returns false. + Otherwise, computes refraction vector, stores it in dest, and returns true. Parameters: | *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **N** *❗️ normalized ❗️* normal vector - | *[in]* **eta** ratio of indices of refraction ( η ) - | *[out]* **dest** destination: refraction result + | *[in]* **eta** ratio of indices of refraction (incident/transmitted) + | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise + + Returns: + returns true if refraction occurs; false if total internal reflection occurs. diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 07412c60..91c16b9a 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -535,15 +535,20 @@ Functions documentation | *[in]* **N** *❗️ normalized ❗️* normal vector | *[out]* **dest** destination: reflection result -.. c:function:: void glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) +.. c:function:: bool glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) - Refraction vector using entering ray, surface normal and refraction index - - If the angle between the entering ray I and the surface normal N is too - great for a given refraction index, the return value is zero + + Computes refraction vector for an incident vector and a surface normal. + + Calculates the refraction vector based on Snell's law. If total internal reflection + occurs (angle too great given eta), dest is set to zero and returns false. + Otherwise, computes refraction vector, stores it in dest, and returns true. Parameters: | *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **N** *❗️ normalized ❗️* normal vector - | *[in]* **eta** ratio of indices of refraction ( η ) - | *[out]* **dest** destination: refraction result + | *[in]* **eta** ratio of indices of refraction (incident/transmitted) + | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise + + Returns: + returns true if refraction occurs; false if total internal reflection occurs. \ No newline at end of file diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index df270e75..04c3a82e 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -427,7 +427,7 @@ Functions documentation | *[in]* **src** pointer to an array of floats | *[out]* **dest** destination vector -.. c:function:: void glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) +.. c:function:: bool glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) Reflection vector using an incident ray and a surface normal @@ -436,19 +436,23 @@ Functions documentation | *[in]* **N** *❗️ normalized ❗️* normal vector | *[out]* **dest** destination: reflection result -.. c:function:: void glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) +.. c:function:: bool glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) - Refraction vector using entering ray, surface normal and refraction index - - If the angle between the entering ray I and the surface normal N is too - great for a given refraction index, the return value is zero - - this implementation does not explicitly preserve the 'w' component of the + computes refraction vector for an incident vector and a surface normal. + + Calculates the refraction vector based on Snell's law. If total internal reflection + occurs (angle too great given eta), dest is set to zero and returns false. + Otherwise, computes refraction vector, stores it in dest, and returns true. + + This implementation does not explicitly preserve the 'w' component of the incident vector 'I' in the output 'dest', users requiring the preservation of the 'w' component should manually adjust 'dest' after calling this function. Parameters: | *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **N** *❗️ normalized ❗️* normal vector - | *[in]* **eta** ratio of indices of refraction ( η ) - | *[out]* **dest** destination: refraction result + | *[in]* **eta** ratio of indices of refraction (incident/transmitted) + | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise + + Returns: + returns true if refraction occurs; false if total internal reflection occurs. \ No newline at end of file diff --git a/include/cglm/call/vec2.h b/include/cglm/call/vec2.h index bb6e629d..2343d145 100644 --- a/include/cglm/call/vec2.h +++ b/include/cglm/call/vec2.h @@ -202,7 +202,7 @@ void glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest); CGLM_EXPORT -void +bool glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest); #ifdef __cplusplus diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index b24529c7..2bde3ba6 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -343,7 +343,7 @@ void glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest); CGLM_EXPORT -void +bool glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest); #ifdef __cplusplus diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 207bc794..d121bea0 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -316,7 +316,7 @@ void glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest); CGLM_EXPORT -void +bool glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest); #ifdef __cplusplus diff --git a/include/cglm/struct/vec2.h b/include/cglm/struct/vec2.h index 7a48bce7..3540d32e 100644 --- a/include/cglm/struct/vec2.h +++ b/include/cglm/struct/vec2.h @@ -55,7 +55,7 @@ CGLM_INLINE vec2s glms_vec2_lerp(vec2s from, vec2s to, float t) CGLM_INLINE vec2s glms_vec2_make(float * restrict src) CGLM_INLINE vec2s glms_vec2_reflect(vec2s I, vec2s N) - CGLM_INLINE vec2s glms_vec2_refract(vec2s I, vec2s N, float eta) + CGLM_INLINE bool glms_vec2_refract(vec2s I, vec2s N, float eta, vec2s *dest) */ #ifndef cglms_vec2s_h @@ -709,22 +709,23 @@ glms_vec2_(reflect)(vec2s I, vec2s N) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @param[out] dest refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -vec2s -glms_vec2_(refract)(vec2s I, vec2s N, float eta) { - vec2s dest; - glm_vec2_refract(I.raw, N.raw, eta, dest.raw); - return dest; +bool +glms_vec2_(refract)(vec2s I, vec2s N, float eta, vec2s * __restrict dest) { + return glm_vec2_refract(I.raw, N.raw, eta, dest->raw); } #endif /* cglms_vec2s_h */ diff --git a/include/cglm/struct/vec3.h b/include/cglm/struct/vec3.h index 3be40991..e1e0a29a 100644 --- a/include/cglm/struct/vec3.h +++ b/include/cglm/struct/vec3.h @@ -78,7 +78,7 @@ CGLM_INLINE vec3s glms_vec3_make(float * restrict src); CGLM_INLINE vec3s glms_vec3_faceforward(vec3s N, vec3s I, vec3s Nref); CGLM_INLINE vec3s glms_vec3_reflect(vec3s I, vec3s N); - CGLM_INLINE vec3s glms_vec3_refract(vec3s I, vec3s N, float eta); + CGLM_INLINE bool glms_vec3_refract(vec3s I, vec3s N, float eta, vec3s *dest) Convenient: CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); @@ -1120,22 +1120,23 @@ glms_vec3_(reflect)(vec3s I, vec3s N) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @returns refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -vec3s -glms_vec3_(refract)(vec3s I, vec3s N, float eta) { - vec3s dest; - glm_vec3_refract(I.raw, N.raw, eta, dest.raw); - return dest; +bool +glms_vec3_(refract)(vec3s I, vec3s N, float eta, vec3s * __restrict dest) { + return glm_vec3_refract(I.raw, N.raw, eta, dest->raw); } #endif /* cglms_vec3s_h */ diff --git a/include/cglm/struct/vec4.h b/include/cglm/struct/vec4.h index 71e441fb..44314608 100644 --- a/include/cglm/struct/vec4.h +++ b/include/cglm/struct/vec4.h @@ -68,7 +68,7 @@ CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask); CGLM_INLINE vec4s glms_vec4_make(float * restrict src); CGLM_INLINE vec4s glms_vec4_reflect(vec4s I, vec4s N); - CGLM_INLINE vec4s glms_vec4_refract(vec4s I, vec4s N, float eta); + CGLM_INLINE bool glms_vec4_refract(vec4s I, vec4s N, float eta, vec4s *dest) */ #ifndef cglms_vec4s_h @@ -945,10 +945,11 @@ glms_vec4_(reflect)(vec4s I, vec4s N) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * this implementation does not explicitly preserve the 'w' component of the * incident vector 'I' in the output 'dest', users requiring the preservation of @@ -956,15 +957,15 @@ glms_vec4_(reflect)(vec4s I, vec4s N) { * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @returns refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -vec4s -glms_vec4_(refract)(vec4s I, vec4s N, float eta) { - vec4s dest; - glm_vec4_refract(I.raw, N.raw, eta, dest.raw); - return dest; +bool +glms_vec4_(refract)(vec4s I, vec4s N, float eta, vec4s * __restrict dest) { + return glm_vec4_refract(I.raw, N.raw, eta, dest->raw); } #endif /* cglms_vec4s_h */ diff --git a/include/cglm/vec2.h b/include/cglm/vec2.h index 58878f55..24655297 100644 --- a/include/cglm/vec2.h +++ b/include/cglm/vec2.h @@ -729,18 +729,21 @@ glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @param[out] dest refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -void +bool glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) { float ndi, eni, k; @@ -750,11 +753,12 @@ glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) { if (k < 0.0f) { glm_vec2_zero(dest); - return; + return false; } glm_vec2_scale(I, eta, dest); glm_vec2_mulsubs(N, eni + sqrtf(k), dest); + return true; } #endif /* cglm_vec2_h */ diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index b3dcfeab..8fc06802 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -1243,18 +1243,21 @@ glm_vec3_reflect(vec3 I, vec3 N, vec3 dest) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @param[out] dest refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -void +bool glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) { float ndi, eni, k; @@ -1264,11 +1267,12 @@ glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) { if (k < 0.0f) { glm_vec3_zero(dest); - return; + return false; } glm_vec3_scale(I, eta, dest); glm_vec3_mulsubs(N, eni + sqrtf(k), dest); + return true; } #endif /* cglm_vec3_h */ diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index d8c2ea07..8c61c19a 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -1326,10 +1326,11 @@ glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) { } /*! - * @brief refraction vector using entering ray, surface normal and refraction index + * @brief computes refraction vector for an incident vector and a surface normal. * - * if the angle between the entering ray I and the surface normal N is too great - * for a given refraction index, the return value is zero + * calculates the refraction vector based on Snell's law. If total internal reflection + * occurs (angle too great given eta), dest is set to zero and returns false. + * Otherwise, computes refraction vector, stores it in dest, and returns true. * * this implementation does not explicitly preserve the 'w' component of the * incident vector 'I' in the output 'dest', users requiring the preservation of @@ -1337,11 +1338,13 @@ glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) { * * @param[in] I normalized incident vector * @param[in] N normalized normal vector - * @param[in] eta ratio of indices of refraction - * @param[out] dest refraction result + * @param[in] eta ratio of indices of refraction (incident/transmitted) + * @param[out] dest refraction vector if refraction occurs; zero vector otherwise + * + * @returns true if refraction occurs; false if total internal reflection occurs. */ CGLM_INLINE -void +bool glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) { float ndi, eni, k; @@ -1351,11 +1354,12 @@ glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) { if (k < 0.0f) { glm_vec4_zero(dest); - return; + return false; } glm_vec4_scale(I, eta, dest); glm_vec4_mulsubs(N, eni + sqrtf(k), dest); + return true; } #endif /* cglm_vec4_h */ diff --git a/src/vec2.c b/src/vec2.c index 27716c4a..4f638a1b 100644 --- a/src/vec2.c +++ b/src/vec2.c @@ -310,7 +310,7 @@ glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest) { } CGLM_EXPORT -void +bool glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) { - glm_vec2_refract(I, N, eta, dest); + return glm_vec2_refract(I, N, eta, dest); } diff --git a/src/vec3.c b/src/vec3.c index 33f3bc47..a31ce3fb 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -473,7 +473,7 @@ glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest) { } CGLM_EXPORT -void +bool glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) { - glm_vec3_refract(I, N, eta, dest); + return glm_vec3_refract(I, N, eta, dest); } diff --git a/src/vec4.c b/src/vec4.c index be0cbbce..de234627 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -431,7 +431,7 @@ glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest) { } CGLM_EXPORT -void +bool glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) { - glm_vec4_refract(I, N, eta, dest); + return glm_vec4_refract(I, N, eta, dest); } diff --git a/test/src/test_vec2.h b/test/src/test_vec2.h index 32231653..59a398bb 100644 --- a/test/src/test_vec2.h +++ b/test/src/test_vec2.h @@ -785,35 +785,40 @@ TEST_IMPL(GLM_PREFIX, vec2_refract) { vec2 N = {0.0f, 1.0f}; /* Surface normal */ vec2 dest; float eta; + float r; /* Water to Air (eta = 1.33/1.0) */ eta = 1.33f / 1.0f; - GLM(vec2_refract)(I, N, eta, dest); + r = GLM(vec2_refract)(I, N, eta, dest); // In 2D, we expect a similar bending behavior as in 3D, so we check dest[1] if (!(dest[0] == 0.0f && dest[1] == 0.0f)) { ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal + ASSERT(r == true); } else { ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection + ASSERT(r == false); } /* Air to Glass (eta = 1.0 / 1.5) */ eta = 1.0f / 1.5f; - GLM(vec2_refract)(I, N, eta, dest); + r = GLM(vec2_refract)(I, N, eta, dest); ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal /* Glass to Water (eta = 1.5 / 1.33) */ eta = 1.5f / 1.33f; - GLM(vec2_refract)(I, N, eta, dest); + r = GLM(vec2_refract)(I, N, eta, dest); ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal, less bending than air to glass /* Diamond to Air (eta = 2.42 / 1.0) */ eta = 2.42f / 1.0f; - GLM(vec2_refract)(I, N, eta, dest); + r = GLM(vec2_refract)(I, N, eta, dest); if (!(dest[0] == 0.0f && dest[1] == 0.0f)) { /* High potential for total internal reflection, but if it occurs, expect significant bending */ ASSERT(dest[1] < -sqrtf(0.5f)); + ASSERT(r == true); } else { ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection + ASSERT(r == false); } TEST_SUCCESS diff --git a/test/src/test_vec3.h b/test/src/test_vec3.h index 6fe4df97..3111b097 100644 --- a/test/src/test_vec3.h +++ b/test/src/test_vec3.h @@ -1890,38 +1890,43 @@ TEST_IMPL(GLM_PREFIX, vec3_refract) { vec3 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */ vec3 dest; float eta; + bool r; /* Water to Air (eta = 1.33/1.0) */ eta = 1.33f / 1.0f; - GLM(vec3_refract)(I, N, eta, dest); + r = GLM(vec3_refract)(I, N, eta, dest); if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) { ASSERT(dest[1] < -sqrtf(0.5f)); + ASSERT(r == true); } else { ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f); + ASSERT(r == false); } /* Air to Glass (eta = 1.0 / 1.5) */ eta = 1.0f / 1.5f; - GLM(vec3_refract)(I, N, eta, dest); + r = GLM(vec3_refract)(I, N, eta, dest); /* Expect bending towards the normal */ ASSERT(dest[1] < -sqrtf(0.5f)); /* Glass to Water (eta = 1.5 / 1.33) */ eta = 1.5f / 1.33f; - GLM(vec3_refract)(I, N, eta, dest); + r = GLM(vec3_refract)(I, N, eta, dest); /* Expect bending towards the normal, less bending than air to glass */ ASSERT(dest[1] < -sqrtf(0.5f)); /* Diamond to Air (eta = 2.42 / 1.0) */ eta = 2.42f / 1.0f; - GLM(vec3_refract)(I, N, eta, dest); + r = GLM(vec3_refract)(I, N, eta, dest); if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) { /* High potential for total internal reflection, but if it occurs, expect significant bending */ ASSERT(dest[1] < -sqrtf(0.5f)); + ASSERT(r == true); } else { ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f); + ASSERT(r == false); } TEST_SUCCESS diff --git a/test/src/test_vec4.h b/test/src/test_vec4.h index 4df471c6..c239d522 100644 --- a/test/src/test_vec4.h +++ b/test/src/test_vec4.h @@ -1575,10 +1575,11 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) { vec4 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */ vec4 dest; float eta; + float r; /* Water to Air (eta = 1.33/1.0) */ eta = 1.33f / 1.0f; - GLM(vec4_refract)(I, N, eta, dest); + r = GLM(vec4_refract)(I, N, eta, dest); if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) { ASSERT(dest[1] < -sqrtf(0.5f)); } else { @@ -1587,17 +1588,17 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) { /* Air to Glass (eta = 1.0 / 1.5) */ eta = 1.0f / 1.5f; - GLM(vec4_refract)(I, N, eta, dest); + r = GLM(vec4_refract)(I, N, eta, dest); ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal /* Glass to Water (eta = 1.5 / 1.33) */ eta = 1.5f / 1.33f; - GLM(vec4_refract)(I, N, eta, dest); + r = GLM(vec4_refract)(I, N, eta, dest); ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal, less bending than air to glass /* Diamond to Air (eta = 2.42 / 1.0) */ eta = 2.42f / 1.0f; - GLM(vec4_refract)(I, N, eta, dest); + r = GLM(vec4_refract)(I, N, eta, dest); if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) { /* High potential for total internal reflection, but if it occurs, expect significant bending */ ASSERT(dest[1] < -sqrtf(0.5f));