atteneder / KtxUnity

Load KTX and Basis Universal textures at runtime
Apache License 2.0
215 stars 42 forks source link

Support of ASTC with various sized blocks #81

Closed cvetelinast closed 1 year ago

cvetelinast commented 1 year ago

Hi, is there currently a way to decompress ktx2 to ASTC with different than 4x4 sizes of the blocks, for example, 5x5, 8x8, etc? We're working on a VR app for Quest 2 and they recommend preferring the format ASTC, but using the GraphicsFormat.RGBA_ASTC4X4_SRGB blocks don't give better results than GraphicsFormat.RGB_ETC2_SRGB neither for time nor for memory. The ktx.h has some enums like ktx_pack_astc_block_dimension_e, and they seem to support this more advanced functionality, although I don't know how much of this is exposed to the native interface.

cvetelinast commented 1 year ago

If anyone is still wondering how to make KtxUnity support the ASTC with different blocks - you can add in KtxNativeInstance.cs static GraphicsFormat GetGraphicsFormat(VkFormat vkFormat) the cases for the blocks that you're interested in. ASTC8x8 is already supported. You can also force-use ASTC4x4 if you add it to the list allFormats at the first position.

To compress an ASTC texture with various blocks, you can use the steps: 1) https://github.com/ARM-software/astc-encoder > astcenc -cs texture.png texture_astc_12x12.ktx 12x12 -medium The output is ktx version 1 image and this library only works with ktx version 2, so you should convert version 1 to 2: 2) https://github.com/KhronosGroup/KTX-Software > ktx2ktx2.exe texture_astc_12x12.ktx The output is ktx version 2. 3) Paste the ktx2 image in StreamingAssets and load it in Unity as this Readme shows.

Unfortunately, after multiple experiments with the texture formats, ASTC with larger block sizes only shows less memory used, but the FPS is not better, so for now, this approach is useless for our scenario. I wish you more luck with that.