From ad64b4f2df8879b45d1f07838edee4a3decab614 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Wed, 21 Feb 2024 09:36:37 +0000 Subject: [PATCH] IES Loader Updated IES loader to use torque math functions and calls in the problem areas for mac and linux. New F32_MIN_EX which is lower than F32_MIN (required for ies profiles) --- .../gfx/bitmap/loaders/ies/ies_loader.cpp | 26 ++++++++++--------- Engine/source/platform/types.h | 1 + Engine/source/platform/typesLinux.h | 1 + Engine/source/platform/typesWin32.h | 1 + Engine/source/platform/typesX86UNIX.h | 1 + 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Engine/source/gfx/bitmap/loaders/ies/ies_loader.cpp b/Engine/source/gfx/bitmap/loaders/ies/ies_loader.cpp index 48602fc9f..3df8c32bd 100644 --- a/Engine/source/gfx/bitmap/loaders/ies/ies_loader.cpp +++ b/Engine/source/gfx/bitmap/loaders/ies/ies_loader.cpp @@ -39,8 +39,10 @@ #include #include +#include "math/mMathFn.h" + IESFileInfo::IESFileInfo() - : _cachedIntegral(std::numeric_limits::max()) + : _cachedIntegral(F32_MAX) , _error("No data loaded") { } @@ -117,7 +119,7 @@ IESLoadHelper::load(const std::string& data, IESFileInfo& info) } this->getFloat(dataPos, dataPos, info.totalLights); - if (info.totalLights < 0 || info.totalLights > std::numeric_limits::max()) + if (info.totalLights < 0 || info.totalLights > F32_MAX) { info._error = "Light Count is not valid"; return false; @@ -138,14 +140,14 @@ IESLoadHelper::load(const std::string& data, IESFileInfo& info) } this->getInt(dataPos, dataPos, info.anglesNumV); - if (info.anglesNumV < 0 || info.anglesNumV > std::numeric_limits::max()) + if (info.anglesNumV < 0 || info.anglesNumV > F32_MAX) { info._error = "VAnglesNum is not valid"; return false; } this->getInt(dataPos, dataPos, info.anglesNumH); - if (info.anglesNumH < 0 || info.anglesNumH > std::numeric_limits::max()) + if (info.anglesNumH < 0 || info.anglesNumH > F32_MAX) { info._error = "HAnglesNum is not valid"; return false; @@ -162,8 +164,8 @@ IESLoadHelper::load(const std::string& data, IESFileInfo& info) this->getFloat(dataPos, dataPos, info.futureUse); this->getFloat(dataPos, dataPos, info.inputWatts); - float minSoFarV = std::numeric_limits::lowest(); - float minSoFarH = std::numeric_limits::lowest(); + float minSoFarV = F32_MIN_EX; + float minSoFarH = F32_MIN_EX; info._anglesV.reserve(info.anglesNumV); info._anglesH.reserve(info.anglesNumH); @@ -358,16 +360,16 @@ IESLoadHelper::saveAsPreview(const IESFileInfo& info, std::uint8_t* data, std::u float lz = -0.5f - 0.0f; // normalize - float length = std::sqrt(lx * lx + ly * ly + lz * lz); + float length = mSqrt(lx * lx + ly * ly + lz * lz); lx /= length; ly /= length; lz /= length; - float angle = 1.0 - std::acos(lx * 0.0 + ly * -1.0 + lz * 0.0f) / 3.141592654; + float angle = 1.0 - mAcos(lx * 0.0 + ly * -1.0 + lz * 0.0f) / 3.141592654; float intensity = ies[angle * 255] * maxValue / length; - std::uint8_t value = std::min(std::max((int)std::floor(TonemapHable(intensity) / TonemapHable(maxValue) * 255.0f), 0), 255); + std::uint8_t value = std::min(std::max((int)mFloor(TonemapHable(intensity) / TonemapHable(maxValue) * 255.0f), 0), 255); switch (channel) { @@ -490,8 +492,8 @@ IESLoadHelper::interpolatePoint(const IESFileInfo& info, std::uint32_t x, std::u float IESLoadHelper::interpolateBilinear(const IESFileInfo& info, float x, float y) const { - int ix = (int)std::floor(x); - int iy = (int)std::floor(y); + int ix = (int)mFloor(x); + int iy = (int)mFloor(y); float fracX = x - ix; float fracY = y - iy; @@ -576,4 +578,4 @@ IESLoadHelper::getInt(const std::string& data, std::string& next, std::int32_t& getLineContent(data, next, line, stopOnWhiteSpace, stopOnComma); assert(!line.empty()); ret = std::atoi(line.c_str()); -} \ No newline at end of file +} diff --git a/Engine/source/platform/types.h b/Engine/source/platform/types.h index 9acdefae0..669659b92 100644 --- a/Engine/source/platform/types.h +++ b/Engine/source/platform/types.h @@ -100,6 +100,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1); ///< Constant static const S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32 static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32 +static const F32 F32_MIN_EX = F32(-3.40282347e+38); ///< Constant Min Limit F32 static const F32 F32_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32 static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32 diff --git a/Engine/source/platform/typesLinux.h b/Engine/source/platform/typesLinux.h index f3b851028..0acb698b9 100644 --- a/Engine/source/platform/typesLinux.h +++ b/Engine/source/platform/typesLinux.h @@ -73,6 +73,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1); static const S32 S32_MAX = S32(2147483647); static const U32 U32_MAX = U32(0xffffffff); +static const F32 F32_MIN_EX = F32(-3.40282347e+38); static const F32 F32_MAX = F32(3.402823466e+38F); static const F32 F32_MIN = F32(1.175494351e-38F); diff --git a/Engine/source/platform/typesWin32.h b/Engine/source/platform/typesWin32.h index 029b1a341..8d96b3bfb 100644 --- a/Engine/source/platform/typesWin32.h +++ b/Engine/source/platform/typesWin32.h @@ -116,6 +116,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1); ///< Constant static const S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32 static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32 +static const F32 F32_MIN_EX = F32(-3.40282347e+38); ///< Constant Min Limit F32 static const F32 F32_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32 static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32 diff --git a/Engine/source/platform/typesX86UNIX.h b/Engine/source/platform/typesX86UNIX.h index 56ba18679..a9b4ab31e 100644 --- a/Engine/source/platform/typesX86UNIX.h +++ b/Engine/source/platform/typesX86UNIX.h @@ -73,6 +73,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1); static const S32 S32_MAX = S32(2147483647); static const U32 U32_MAX = U32(0xffffffff); +static const F32 F32_MIN_EX = F32(-3.40282347e+38); static const F32 F32_MAX = F32(3.402823466e+38F); static const F32 F32_MIN = F32(1.175494351e-38F);