From c13622c5afcf74426c9ca6d05cb866893cd436b9 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Fri, 21 Jan 2022 16:07:27 -0600 Subject: [PATCH] Handled special case logic for SNORM minimum value conversion Signed-off-by: Chris Galvan --- .../Source/RPI.Reflect/Image/StreamingImageAsset.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp index 76260f506e..1ed900b2b8 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp @@ -146,8 +146,12 @@ namespace AZ case AZ::RHI::Format::R8_SNORM: { // Scale the value from AZ::s8 min/max to -1 to 1 + // We need to treat -128 and -127 the same, so that we get a symmetric + // range of -127 to 127 with complementary scaled values of -1 to 1 auto actualMem = reinterpret_cast(mem); - return ScaleValue(actualMem[index], std::numeric_limits::min(), std::numeric_limits::max(), -1, 1); + AZ::s8 signedMax = std::numeric_limits::max(); + AZ::s8 signedMin = aznumeric_cast(-signedMax); + return ScaleValue(AZStd::max(actualMem[index], signedMin), signedMin, signedMax, -1, 1); } case AZ::RHI::Format::D16_UNORM: case AZ::RHI::Format::R16_UNORM: @@ -157,8 +161,12 @@ namespace AZ case AZ::RHI::Format::R16_SNORM: { // Scale the value from AZ::s16 min/max to -1 to 1 + // We need to treat -32768 and -32767 the same, so that we get a symmetric + // range of -32767 to 32767 with complementary scaled values of -1 to 1 auto actualMem = reinterpret_cast(mem); - return ScaleValue(actualMem[index], std::numeric_limits::min(), std::numeric_limits::max(), -1, 1); + AZ::s16 signedMax = std::numeric_limits::max(); + AZ::s16 signedMin = aznumeric_cast(-signedMax); + return ScaleValue(AZStd::max(actualMem[index], signedMin), signedMin, signedMax, -1, 1); } case AZ::RHI::Format::R16_FLOAT: {