microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

Home Page:https://walbourn.github.io/introducing-directxmath/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DirectXTex converts floating point numbers to integers by different way between BC4 and BC5.

yosshin4004 opened this issue · comments

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);

Sorry, I sent it by mistake.
This issue is for DirectXTex.