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:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user