Skip to content

Commit

Permalink
GLTF Builder: improved precsion of float->U8 and float->S8 conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jun 15, 2023
1 parent 43ffb3a commit 7429aab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions AssetLoader/src/GLTFBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ inline void ConvertElement(DstType& Dst, const SrcType& Src)
template <>
inline void ConvertElement<float, Uint8>(Uint8& Dst, const float& Src)
{
Dst = static_cast<Uint8>(clamp(Src * 255.f, 0.f, 255.f));
Dst = static_cast<Uint8>(clamp(Src * 255.f + 0.5f, 0.f, 255.f));
}

template <>
inline void ConvertElement<float, Int8>(Int8& Dst, const float& Src)
{
Dst = static_cast<Int8>(clamp(Src * 127.f, -127.f, 127.f));
auto r = Src > 0.f ? +0.5f : -0.5f;
Dst = static_cast<Int8>(clamp(Src * 127.f + r, -127.f, 127.f));
}

template <typename SrcType, typename DstType>
Expand Down

0 comments on commit 7429aab

Please sign in to comment.