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)
This commit is contained in:
marauder2k7 2024-02-21 09:36:37 +00:00
parent 39ec0305f9
commit ad64b4f2df
5 changed files with 18 additions and 12 deletions

View file

@ -39,8 +39,10 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include "math/mMathFn.h"
IESFileInfo::IESFileInfo() IESFileInfo::IESFileInfo()
: _cachedIntegral(std::numeric_limits<float>::max()) : _cachedIntegral(F32_MAX)
, _error("No data loaded") , _error("No data loaded")
{ {
} }
@ -117,7 +119,7 @@ IESLoadHelper::load(const std::string& data, IESFileInfo& info)
} }
this->getFloat(dataPos, dataPos, info.totalLights); this->getFloat(dataPos, dataPos, info.totalLights);
if (info.totalLights < 0 || info.totalLights > std::numeric_limits<short>::max()) if (info.totalLights < 0 || info.totalLights > F32_MAX)
{ {
info._error = "Light Count is not valid"; info._error = "Light Count is not valid";
return false; return false;
@ -138,14 +140,14 @@ IESLoadHelper::load(const std::string& data, IESFileInfo& info)
} }
this->getInt(dataPos, dataPos, info.anglesNumV); this->getInt(dataPos, dataPos, info.anglesNumV);
if (info.anglesNumV < 0 || info.anglesNumV > std::numeric_limits<short>::max()) if (info.anglesNumV < 0 || info.anglesNumV > F32_MAX)
{ {
info._error = "VAnglesNum is not valid"; info._error = "VAnglesNum is not valid";
return false; return false;
} }
this->getInt(dataPos, dataPos, info.anglesNumH); this->getInt(dataPos, dataPos, info.anglesNumH);
if (info.anglesNumH < 0 || info.anglesNumH > std::numeric_limits<short>::max()) if (info.anglesNumH < 0 || info.anglesNumH > F32_MAX)
{ {
info._error = "HAnglesNum is not valid"; info._error = "HAnglesNum is not valid";
return false; 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.futureUse);
this->getFloat(dataPos, dataPos, info.inputWatts); this->getFloat(dataPos, dataPos, info.inputWatts);
float minSoFarV = std::numeric_limits<float>::lowest(); float minSoFarV = F32_MIN_EX;
float minSoFarH = std::numeric_limits<float>::lowest(); float minSoFarH = F32_MIN_EX;
info._anglesV.reserve(info.anglesNumV); info._anglesV.reserve(info.anglesNumV);
info._anglesH.reserve(info.anglesNumH); 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; float lz = -0.5f - 0.0f;
// normalize // normalize
float length = std::sqrt(lx * lx + ly * ly + lz * lz); float length = mSqrt(lx * lx + ly * ly + lz * lz);
lx /= length; lx /= length;
ly /= length; ly /= length;
lz /= 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; 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) switch (channel)
{ {
@ -490,8 +492,8 @@ IESLoadHelper::interpolatePoint(const IESFileInfo& info, std::uint32_t x, std::u
float float
IESLoadHelper::interpolateBilinear(const IESFileInfo& info, float x, float y) const IESLoadHelper::interpolateBilinear(const IESFileInfo& info, float x, float y) const
{ {
int ix = (int)std::floor(x); int ix = (int)mFloor(x);
int iy = (int)std::floor(y); int iy = (int)mFloor(y);
float fracX = x - ix; float fracX = x - ix;
float fracY = y - iy; 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); getLineContent(data, next, line, stopOnWhiteSpace, stopOnComma);
assert(!line.empty()); assert(!line.empty());
ret = std::atoi(line.c_str()); ret = std::atoi(line.c_str());
} }

View file

@ -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 S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32
static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32 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_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32
static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32 static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32

View file

@ -73,6 +73,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1);
static const S32 S32_MAX = S32(2147483647); static const S32 S32_MAX = S32(2147483647);
static const U32 U32_MAX = U32(0xffffffff); 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_MAX = F32(3.402823466e+38F);
static const F32 F32_MIN = F32(1.175494351e-38F); static const F32 F32_MIN = F32(1.175494351e-38F);

View file

@ -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 S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32
static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32 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_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32
static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32 static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32

View file

@ -73,6 +73,7 @@ static const S32 S32_MIN = S32(-2147483647 - 1);
static const S32 S32_MAX = S32(2147483647); static const S32 S32_MAX = S32(2147483647);
static const U32 U32_MAX = U32(0xffffffff); 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_MAX = F32(3.402823466e+38F);
static const F32 F32_MIN = F32(1.175494351e-38F); static const F32 F32_MIN = F32(1.175494351e-38F);