Skip to content

Commit

Permalink
CppSl.sl lerp() functions check if end points are equal.
Browse files Browse the repository at this point in the history
lerp() functions now check if end points are equal to avoid floating-point arthimetic errors.
  • Loading branch information
AndrewRichards-Code committed Aug 23, 2024
1 parent 2b98aee commit e0c7c55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CrossPlatform/Shaders/CppSl.sl
Original file line number Diff line number Diff line change
Expand Up @@ -822,23 +822,36 @@
template <typename T>
T lerp(const T& a, const T& b, const T& x)
{
return b * x + a * (T(1.0) - x);
if (a == b)
return a;

T c = b * x + a * (T(1.0) - x);
return c;
}
template <typename T>
tvector2<T> lerp(const tvector2<T>& a, const tvector2<T>& b, const T& x)
{
if (a == b)
return a;

tvector2 c = b * x + a * (T(1.0) - x);
return c;
}
template<typename T>
tvector3<T> lerp(const tvector3<T>& a, const tvector3<T>& b, const T& x)
{
if (a == b)
return a;

tvector3 c = b * x + a * (T(1.0) - x);
return c;
}
template <typename T>
tvector4<T> lerp(const tvector4<T>& a, const tvector4<T>& b, const T& x)
{
if (a == b)
return a;

tvector4 c = b * x + a * (T(1.0) - x);
return c;
}
Expand Down
2 changes: 1 addition & 1 deletion CrossPlatform/Shaders/common.sl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ uint3 UnflattenArrayIndex(uint idx, uint2 size)
uint z = idx / (size.x * size.y);
idx -= (z * size.x * size.y);
uint y = idx / size.x;
uint x = idx % size.x;
uint x = idx % size.x;
return uint3(x, y, z);
}

Expand Down

0 comments on commit e0c7c55

Please sign in to comment.