Browse Source

Modify glm::refract according to GLSL man page: return vector zero when full reflection happens #806

tigertang 7 years ago
parent
commit
84b6247093
2 changed files with 2 additions and 5 deletions
  1. 2 3
      glm/detail/func_geometric.inl
  2. 0 2
      glm/geometric.hpp

+ 2 - 3
glm/detail/func_geometric.inl

@@ -114,11 +114,10 @@ namespace detail
 	{
 	{
 		GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& I, vec<L, T, Q> const& N, T eta)
 		GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& I, vec<L, T, Q> const& N, T eta)
 		{
 		{
-			assert(eta >= static_cast<T>(-1) && eta <= static_cast<T>(1));
-
 			T const dotValue(dot(N, I));
 			T const dotValue(dot(N, I));
 			T const k(static_cast<T>(1) - eta * eta * (static_cast<T>(1) - dotValue * dotValue));
 			T const k(static_cast<T>(1) - eta * eta * (static_cast<T>(1) - dotValue * dotValue));
-			vec<L, T, Q> const Result = (eta * I - (eta * dotValue + std::sqrt(k)) * N) * static_cast<T>(k >= static_cast<T>(0));
+			vec<L, T, Q> const Result =
+                (k >= static_cast<T>(0)) ? (eta * I - (eta * dotValue + std::sqrt(k)) * N) : vec<L, T, Q>(0);
 			return Result;
 			return Result;
 		}
 		}
 	};
 	};

+ 0 - 2
glm/geometric.hpp

@@ -99,8 +99,6 @@ namespace glm
 	/// and the ratio of indices of refraction eta,
 	/// and the ratio of indices of refraction eta,
 	/// return the refraction vector.
 	/// return the refraction vector.
 	///
 	///
-	/// @param eta Indice of refraction. Must be a value between -1 and 1 inclusively.
-	///
 	/// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
 	/// @tparam L An integer between 1 and 4 included that qualify the dimension of the vector.
 	/// @tparam T Floating-point scalar types.
 	/// @tparam T Floating-point scalar types.
 	///
 	///