From 31ae44771d9776dde131852345f15cac6de9c1d1 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 13 Jan 2020 19:14:01 -0800 Subject: [PATCH] Fix long-standing bug in BC4S / BC5S compression --- DirectXTex/BC.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/DirectXTex/BC.h b/DirectXTex/BC.h index b4cbf23..a69b81a 100644 --- a/DirectXTex/BC.h +++ b/DirectXTex/BC.h @@ -249,12 +249,18 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo uint32_t iStep; if (fDot <= 0.0f) - iStep = ((6 == cSteps) && (pPoints[iPoint] <= fX * 0.5f)) ? 6u : 0u; + { + // D3DX10 / D3DX11 didn't take into account the proper minimum value for the bRange (BC4S/BC5S) case + iStep = ((6 == cSteps) && (pPoints[iPoint] <= (fX + MIN_VALUE) * 0.5f)) ? 6u : 0u; + } else if (fDot >= fSteps) - iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + 1.0f) * 0.5f)) ? 7u : (cSteps - 1); + { + iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + MAX_VALUE) * 0.5f)) ? 7u : (cSteps - 1); + } else + { iStep = uint32_t(fDot + 0.5f); - + } if (iStep < cSteps) {