Browse Source

Fixed mix implementation to improve GLSL conformance #866

Christophe Riccio 6 years ago
parent
commit
6b62e66a7d
2 changed files with 4 additions and 3 deletions
  1. 3 3
      glm/detail/func_common.inl
  2. 1 0
      readme.md

+ 3 - 3
glm/detail/func_common.inl

@@ -84,7 +84,7 @@ namespace detail
 		{
 			GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'mix' only accept floating-point inputs for the interpolator a");
 
-			return vec<L, T, Q>(vec<L, U, Q>(x) + a * vec<L, U, Q>(y - x));
+			return vec<L, T, Q>(vec<L, U, Q>(x) * (static_cast<U>(1) - a) + vec<L, U, Q>(y) * a);
 		}
 	};
 
@@ -107,7 +107,7 @@ namespace detail
 		{
 			GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'mix' only accept floating-point inputs for the interpolator a");
 
-			return vec<L, T, Q>(vec<L, U, Q>(x) + a * vec<L, U, Q>(y - x));
+			return vec<L, T, Q>(vec<L, U, Q>(x) * (static_cast<U>(1) - a) + vec<L, U, Q>(y) * a);
 		}
 	};
 
@@ -127,7 +127,7 @@ namespace detail
 		{
 			GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'mix' only accept floating-point inputs for the interpolator a");
 
-			return static_cast<T>(static_cast<U>(x) + a * static_cast<U>(y - x));
+			return static_cast<T>(static_cast<U>(x) * (static_cast<U>(1) - a) + static_cast<U>(y) * a);
 		}
 	};
 

+ 1 - 0
readme.md

@@ -59,6 +59,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
 #### Fixes:
 - Fixed in mat4x3 conversion #829
 - Fixed constexpr issue on GCC #832
+- Fixed mix implementation to improve GLSL conformance #866
 
 ### [GLM 0.9.9.3](https://github.com/g-truc/glm/releases/tag/0.9.9.3) - 2018-10-31
 #### Features: