atteneder / KtxUnity

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

Building KTX-compressed model textures to iOS #53

Closed seyfeb closed 1 year ago

seyfeb commented 2 years ago

I feel like I’m doing something wrong or I missed the answer when searching the previous issues, because I assume I don’t have a very special use case.

I want to load a glTF file with compressed textures in Unity3D for building an app including those models to iOS (and Android) devices. I’m loading it via glTFast and the KtxUnity library.

The model I use for testing is the gltfpack-converted Avocado model via ~/bin/gltfpack -i Avocado.gltf -o Avocado_uastc.glb -tc -noq or ~/bin/gltfpack -i Avocado.gltf -o Avocado_uastc.glb -tu -noq to obtain a GLTF model with compressed textures (ect1s or uastc, respectively).

In Unity the importer shows the texture compression as RGB compressed DXT1|BC1 UNorm and there is no way to change the format either for specific platforms (iOS/Android) or in general. However DXT1|BC1 is not supported on iOS. Does anybody know what’s the right way to handle this? 😬

Screen Shot 2022-04-11 at 12 40 45

atteneder commented 2 years ago

Hi @seyfeb,

Which workflow are you aiming for?

  1. Design-Time Import (Editor Import), where everything (including KTX textures) is converted to Unity Assets, practically leaving the glTF domain at import-time.
  2. Run-Time Loading of glTF, in which case you wouldn't need to copy your glTFs into the Assets folder in first place (except into StreamingAssets, if that's what you want)

If you're going for 1, then prior compressing meshes and textures does not make sense as it introduces compression artifacts. Granted, I never tried that workflow and I don't know if Unity converts that texture to something the target platform can digest.

seyfeb commented 2 years ago

Actually, I’m aiming for 1. right now but for number 2 in the long term. For 2. I infer that there is no problem at all (haven’t tried it yet).

I get your point that compressing first (and then a second time with a different algorithm by the Unity editor) doesn’t make much sense. However, what I actually tried to achieve was to reduce the resolution of the textures. gltfpack lets you do this only in combination with a compression, hence the compressed textures.

For the supported default texture assets (JPG, PNG,..) Unity let’s you choose a desired maximum resolution. The glTFast-imported models do not expose that option. That part of the issue might even be better placed in the glTFast repository (although I seem to be the only one ever using it that way 😀).

Maybe it’s best to shift it to the content-creation part of the workflow and use a different tool for texture resizing of an existing GLB/GLTF file (do you happen to have any recommendations?).

atteneder commented 2 years ago

@seyfeb Have a look at the glTF Project Explorer for tools. Maybe glTF-Transform or Gestaltor do the trick.

atteneder commented 1 year ago

Closing this, since this is an authoring/tooling issue.

fwiw: Next release will allow you to discard the higher resolution mipmap levels, which might just be what you need.