mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
refract
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
CGLM_INLINE void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_reflect(vec2 I, vec2 N, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest)
|
||||
*/
|
||||
|
||||
#ifndef cglm_vec2_h
|
||||
@@ -727,4 +728,33 @@ glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
|
||||
glm_vec2_sub(I, temp, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief 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
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
||||
float ndi, eni, k;
|
||||
|
||||
ndi = glm_vec2_dot(N, I);
|
||||
eni = eta * ndi;
|
||||
k = eta * eta + eni * eni;
|
||||
|
||||
if (k > 1.0f) {
|
||||
glm_vec2_zero(dest);
|
||||
return;
|
||||
}
|
||||
|
||||
glm_vec2_scale(I, eta, dest);
|
||||
glm_vec2_mulsubs(N, eni + sqrt(1.0f - k), dest);
|
||||
}
|
||||
|
||||
#endif /* cglm_vec2_h */
|
||||
|
||||
Reference in New Issue
Block a user