DirectXTex converts floating point numbers to integers by different way between BC4 and BC5.
yosshin4004 opened this issue · comments
yosshin4004 commented
DirectXTex converts floating point numbers to integers by different way between BC4 and BC5.
Is this correct behaviour?
-
In case of BC4: fractions will be cut off.
DecompressBC decodes BC4 pixel block as float precision.
_StoreScanline converts it as DXGI_FORMAT_R8_SNORM by following code.
float v = XMVectorGetX(*sPtr++);
v = std::max<float>(std::min<float>(v, 1.f), -1.f);
*(dPtr++) = static_cast<int8_t>(v * 127.f);
-
In case of BC5: fractions will be round up.
DecompressBC decodes BC5 pixel block as float precision.
_StoreScanline converts it as DXGI_FORMAT_R8G8_SNORM by XMStoreByteN2 as follows.
// Clamp to bounds
XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
vResult = _mm_min_ps(vResult,g_XMOne);
// Scale by multiplication
vResult = _mm_mul_ps(vResult,g_ByteMax);
// Convert to int by rounding
__m128i vInt = _mm_cvtps_epi32(vResult);
yosshin4004 commented
Sorry, I sent it by mistake.
This issue is for DirectXTex.