zeux / meshoptimizer

Mesh optimization library that makes meshes smaller and faster to render
MIT License
5.6k stars 480 forks source link

gltfpack: resize image before basisu conversion #134

Closed arpu closed 4 years ago

arpu commented 4 years ago

Hi, would it be possible to use something like " mogrify -resize 50% *.jpg/png" bevor the basisu use the image data?

zeux commented 4 years ago

The feature makes sense but I don't want to rely on extra command line tools other than basisu. One potential option is to add smth like -mip_skip X to basisu which would allow resizing in 2x increments (50%, 25%, etc) during texture compression.

arpu commented 4 years ago

it would be nice to has some logic, if the image is >=4k => reduce 50% and not on a 2k texture

zeux commented 4 years ago

I'm not sure about this - image size by itself isn't really indicative of the resulting quality - you could have a 4k texture occupy 10x area compared to a 2k texture in which case a 2k texture is worth reducing first. gltfpack could analyze the UV mapping to try to keep density uniform in theory, but I'd need to experiment with this to figure out if this works well in practice on varied gltf content.

zeux commented 4 years ago

This needs a basisu change; the change itself is trivial but it conflicts with https://github.com/BinomialLLC/basis_universal/pull/113 since it touches the same code. I don't want to make any more pull requests up until those get merged, so this will have to wait.

zeux commented 4 years ago

I'm likely going to have to switch to toktx for KTX2 conversion to support UASTC + zstd; looks like toktx has a --scale option (with e.g. --scale 0.25 downscaling everything by 4x4x) which is perfect here; this would mean that gltfpack doesn't support .basis anymore though so it needs to wait until three.js supports ktx2 properly.