summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsTools
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-29 18:26:05 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-29 18:26:05 +0000
commitc27f8e76191778c43bdf0f8ea3a85adc3c0abd7e (patch)
treed58b5c9fe93f75c2fcfd8275de7551c235cfda56 /Graphics/GraphicsTools
parentGraphics Utilities: added ComputeMipLevel function (diff)
downloadDiligentCore-c27f8e76191778c43bdf0f8ea3a85adc3c0abd7e.tar.gz
DiligentCore-c27f8e76191778c43bdf0f8ea3a85adc3c0abd7e.zip
Minor update to SRGBAverage helper function
Diffstat (limited to 'Graphics/GraphicsTools')
-rw-r--r--Graphics/GraphicsTools/src/GraphicsUtilities.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
index 52116d12..93e188fd 100644
--- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
+++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
@@ -136,7 +136,8 @@ void GenerateCheckerBoardPattern(Uint32 Width, Uint32 Height, TEXTURE_FORMAT Fmt
template <typename ChannelType>
ChannelType SRGBAverage(ChannelType c0, ChannelType c1, ChannelType c2, ChannelType c3)
{
- static constexpr float MinVal = static_cast<float>(std::numeric_limits<ChannelType>::min());
+ static_assert(std::numeric_limits<ChannelType>::is_integer && !std::numeric_limits<ChannelType>::is_signed, "Unsigned integers are expected");
+
static constexpr float MaxVal = static_cast<float>(std::numeric_limits<ChannelType>::max());
static constexpr float MaxValInv = 1.f / MaxVal;
@@ -148,7 +149,7 @@ ChannelType SRGBAverage(ChannelType c0, ChannelType c1, ChannelType c2, ChannelT
float fLinearAverage = (FastSRGBToLinear(fc0) + FastSRGBToLinear(fc1) + FastSRGBToLinear(fc2) + FastSRGBToLinear(fc3)) * 0.25f;
float fSRGBAverage = FastLinearToSRGB(fLinearAverage) * MaxVal;
- fSRGBAverage = std::max(fSRGBAverage, MinVal);
+ // Clamping by MaxVal is essential because fast SRGB math is imprecise
fSRGBAverage = std::min(fSRGBAverage, MaxVal);
return static_cast<ChannelType>(fSRGBAverage);