mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
change signature of refraction to let caller know if refraction occurs or not
This commit is contained in:
@@ -406,15 +406,19 @@ Functions documentation
|
|||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[out]* **dest** destination: reflection result
|
| *[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
|
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
|
Calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
great for a given refraction index, the return value is zero
|
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:
|
Parameters:
|
||||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||||
| *[out]* **dest** destination: refraction result
|
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
|
|||||||
@@ -535,15 +535,20 @@ Functions documentation
|
|||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[out]* **dest** destination: reflection result
|
| *[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
|
Computes refraction vector for an incident vector and a surface normal.
|
||||||
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.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||||
| *[out]* **dest** destination: refraction result
|
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
@@ -427,7 +427,7 @@ Functions documentation
|
|||||||
| *[in]* **src** pointer to an array of floats
|
| *[in]* **src** pointer to an array of floats
|
||||||
| *[out]* **dest** destination vector
|
| *[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
|
Reflection vector using an incident ray and a surface normal
|
||||||
|
|
||||||
@@ -436,19 +436,23 @@ Functions documentation
|
|||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[out]* **dest** destination: reflection result
|
| *[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
|
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
|
Calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
great for a given refraction index, the return value is zero
|
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
|
This implementation does not explicitly preserve the 'w' component of the
|
||||||
incident vector 'I' in the output 'dest', users requiring the preservation of
|
incident vector 'I' in the output 'dest', users requiring the preservation of
|
||||||
the 'w' component should manually adjust 'dest' after calling this function.
|
the 'w' component should manually adjust 'dest' after calling this function.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||||
| *[out]* **dest** destination: refraction result
|
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
@@ -202,7 +202,7 @@ void
|
|||||||
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest);
|
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest);
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest);
|
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ void
|
|||||||
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest);
|
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest);
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest);
|
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ void
|
|||||||
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest);
|
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest);
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest);
|
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
CGLM_INLINE vec2s glms_vec2_lerp(vec2s from, vec2s to, float t)
|
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_make(float * restrict src)
|
||||||
CGLM_INLINE vec2s glms_vec2_reflect(vec2s I, vec2s N)
|
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
|
#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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @param[out] dest refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
vec2s
|
bool
|
||||||
glms_vec2_(refract)(vec2s I, vec2s N, float eta) {
|
glms_vec2_(refract)(vec2s I, vec2s N, float eta, vec2s * __restrict dest) {
|
||||||
vec2s dest;
|
return glm_vec2_refract(I.raw, N.raw, eta, dest->raw);
|
||||||
glm_vec2_refract(I.raw, N.raw, eta, dest.raw);
|
|
||||||
return dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglms_vec2s_h */
|
#endif /* cglms_vec2s_h */
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
CGLM_INLINE vec3s glms_vec3_make(float * restrict src);
|
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_faceforward(vec3s N, vec3s I, vec3s Nref);
|
||||||
CGLM_INLINE vec3s glms_vec3_reflect(vec3s I, vec3s N);
|
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:
|
Convenient:
|
||||||
CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b);
|
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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @returns refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
vec3s
|
bool
|
||||||
glms_vec3_(refract)(vec3s I, vec3s N, float eta) {
|
glms_vec3_(refract)(vec3s I, vec3s N, float eta, vec3s * __restrict dest) {
|
||||||
vec3s dest;
|
return glm_vec3_refract(I.raw, N.raw, eta, dest->raw);
|
||||||
glm_vec3_refract(I.raw, N.raw, eta, dest.raw);
|
|
||||||
return dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglms_vec3s_h */
|
#endif /* cglms_vec3s_h */
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
|
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
|
||||||
CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
|
CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
|
||||||
CGLM_INLINE vec4s glms_vec4_reflect(vec4s I, vec4s N);
|
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
|
#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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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
|
* this implementation does not explicitly preserve the 'w' component of the
|
||||||
* incident vector 'I' in the output 'dest', users requiring the preservation of
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @returns refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
vec4s
|
bool
|
||||||
glms_vec4_(refract)(vec4s I, vec4s N, float eta) {
|
glms_vec4_(refract)(vec4s I, vec4s N, float eta, vec4s * __restrict dest) {
|
||||||
vec4s dest;
|
return glm_vec4_refract(I.raw, N.raw, eta, dest->raw);
|
||||||
glm_vec4_refract(I.raw, N.raw, eta, dest.raw);
|
|
||||||
return dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglms_vec4s_h */
|
#endif /* cglms_vec4s_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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @param[out] dest refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
bool
|
||||||
glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
||||||
float ndi, eni, k;
|
float ndi, eni, k;
|
||||||
|
|
||||||
@@ -750,11 +753,12 @@ glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
|||||||
|
|
||||||
if (k < 0.0f) {
|
if (k < 0.0f) {
|
||||||
glm_vec2_zero(dest);
|
glm_vec2_zero(dest);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm_vec2_scale(I, eta, dest);
|
glm_vec2_scale(I, eta, dest);
|
||||||
glm_vec2_mulsubs(N, eni + sqrtf(k), dest);
|
glm_vec2_mulsubs(N, eni + sqrtf(k), dest);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglm_vec2_h */
|
#endif /* cglm_vec2_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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @param[out] dest refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
bool
|
||||||
glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
||||||
float ndi, eni, k;
|
float ndi, eni, k;
|
||||||
|
|
||||||
@@ -1264,11 +1267,12 @@ glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
|||||||
|
|
||||||
if (k < 0.0f) {
|
if (k < 0.0f) {
|
||||||
glm_vec3_zero(dest);
|
glm_vec3_zero(dest);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm_vec3_scale(I, eta, dest);
|
glm_vec3_scale(I, eta, dest);
|
||||||
glm_vec3_mulsubs(N, eni + sqrtf(k), dest);
|
glm_vec3_mulsubs(N, eni + sqrtf(k), dest);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglm_vec3_h */
|
#endif /* cglm_vec3_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
|
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||||
* for a given refraction index, the return value is zero
|
* 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
|
* this implementation does not explicitly preserve the 'w' component of the
|
||||||
* incident vector 'I' in the output 'dest', users requiring the preservation of
|
* 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] I normalized incident vector
|
||||||
* @param[in] N normalized normal vector
|
* @param[in] N normalized normal vector
|
||||||
* @param[in] eta ratio of indices of refraction
|
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||||
* @param[out] dest refraction result
|
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||||
|
*
|
||||||
|
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
bool
|
||||||
glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
||||||
float ndi, eni, k;
|
float ndi, eni, k;
|
||||||
|
|
||||||
@@ -1351,11 +1354,12 @@ glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
|||||||
|
|
||||||
if (k < 0.0f) {
|
if (k < 0.0f) {
|
||||||
glm_vec4_zero(dest);
|
glm_vec4_zero(dest);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm_vec4_scale(I, eta, dest);
|
glm_vec4_scale(I, eta, dest);
|
||||||
glm_vec4_mulsubs(N, eni + sqrtf(k), dest);
|
glm_vec4_mulsubs(N, eni + sqrtf(k), dest);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglm_vec4_h */
|
#endif /* cglm_vec4_h */
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
bool
|
||||||
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -785,35 +785,40 @@ TEST_IMPL(GLM_PREFIX, vec2_refract) {
|
|||||||
vec2 N = {0.0f, 1.0f}; /* Surface normal */
|
vec2 N = {0.0f, 1.0f}; /* Surface normal */
|
||||||
vec2 dest;
|
vec2 dest;
|
||||||
float eta;
|
float eta;
|
||||||
|
float r;
|
||||||
|
|
||||||
/* Water to Air (eta = 1.33/1.0) */
|
/* Water to Air (eta = 1.33/1.0) */
|
||||||
eta = 1.33f / 1.0f;
|
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]
|
// 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)) {
|
if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal
|
ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal
|
||||||
|
ASSERT(r == true);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
||||||
|
ASSERT(r == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||||
eta = 1.0f / 1.5f;
|
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
|
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
|
||||||
|
|
||||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||||
eta = 1.5f / 1.33f;
|
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
|
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) */
|
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||||
eta = 2.42f / 1.0f;
|
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)) {
|
if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
|
||||||
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
ASSERT(r == true);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
||||||
|
ASSERT(r == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_SUCCESS
|
TEST_SUCCESS
|
||||||
|
|||||||
@@ -1890,38 +1890,43 @@ TEST_IMPL(GLM_PREFIX, vec3_refract) {
|
|||||||
vec3 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */
|
vec3 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */
|
||||||
vec3 dest;
|
vec3 dest;
|
||||||
float eta;
|
float eta;
|
||||||
|
bool r;
|
||||||
|
|
||||||
/* Water to Air (eta = 1.33/1.0) */
|
/* Water to Air (eta = 1.33/1.0) */
|
||||||
eta = 1.33f / 1.0f;
|
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)) {
|
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) {
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
ASSERT(r == true);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
||||||
|
ASSERT(r == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||||
eta = 1.0f / 1.5f;
|
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 */
|
/* Expect bending towards the normal */
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
|
||||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||||
eta = 1.5f / 1.33f;
|
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 */
|
/* Expect bending towards the normal, less bending than air to glass */
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
|
||||||
/* Diamond to Air (eta = 2.42 / 1.0) */
|
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||||
eta = 2.42f / 1.0f;
|
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)) {
|
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 */
|
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
ASSERT(r == true);
|
||||||
} else {
|
} else {
|
||||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
||||||
|
ASSERT(r == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_SUCCESS
|
TEST_SUCCESS
|
||||||
|
|||||||
@@ -1575,10 +1575,11 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) {
|
|||||||
vec4 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */
|
vec4 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */
|
||||||
vec4 dest;
|
vec4 dest;
|
||||||
float eta;
|
float eta;
|
||||||
|
float r;
|
||||||
|
|
||||||
/* Water to Air (eta = 1.33/1.0) */
|
/* Water to Air (eta = 1.33/1.0) */
|
||||||
eta = 1.33f / 1.0f;
|
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)) {
|
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) {
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
} else {
|
} else {
|
||||||
@@ -1587,17 +1588,17 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) {
|
|||||||
|
|
||||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||||
eta = 1.0f / 1.5f;
|
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
|
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
|
||||||
|
|
||||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||||
eta = 1.5f / 1.33f;
|
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
|
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) */
|
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||||
eta = 2.42f / 1.0f;
|
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)) {
|
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 */
|
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||||
|
|||||||
Reference in New Issue
Block a user