Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPG images merged into PNG, drastically inflating glb size. #1318

Open
globglob3D opened this issue Jan 27, 2021 · 2 comments
Open

JPG images merged into PNG, drastically inflating glb size. #1318

globglob3D opened this issue Jan 27, 2021 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@globglob3D
Copy link

globglob3D commented Jan 27, 2021

note: depending on how you look at it this might not be a bug, perhaps the user need more control regarding packed image format at export.

Describe the bug
In specific conditions images might be exported as PNG when they should be exported as JPG, which drastically inflate the size of the resulting GLB/GLTF.

To Reproduce/Expected behavior
Have one object with one material applied to it.
Feed the BSDF with a Base Color image texture, a bundled Roughness/Metallic map with separated green channel to Roughness and blue channel to Metallic BSDF inputs. (Base Color and R/M are all JPG)
Feed on AO texture to a glTF Settings group node. (AO is JPG)
Set exporter image format to Automatic.
Export.

Two things may happen:

  • if your AO texture is of different size than your R/M texture they won't get bundled and all of them stay as JPG. That's expected behavior.
  • if your AO texture is the same size than your R/M texture the AO get bundled on the Red channel and the whole image become PNG. This drastically inflate the overall .glb size for no reason.

In short, it seems that anytime the exporter find AO, R, or M textures of the same size that aren't bundled it will ignore their respective format and merge them into a PNG RGB channels. This goes against the Automatic format description which state that JPEG will be exported as JPEG and PNG as PNG.

I don't mind the automatic merging but I would prefer the exporter to check the format of each images before merging and if all are JPG make sure that the resulting image is JPG. To me that's what make the most sense in production.

Screenshots
Setup:
image

AO is 256x256, Base Color and R/M are 1024x1024. Result is 3 light JPG (roughly 100ko*3 = 300ko)
image

All textures are 1024x1024. AO get bundled with R/M and resulting image is a heavy PNG (100ko Base Color + 1.14Mo AO/R/M = 1.24Mo)
image

To be very clear, the size increase is partly due to the AO going from 256 to 1024 but that would be a 100ko difference MAX. The blame is really on the PNG format here.

.blend file/ .gltf
testy-test.zip

Version
Windows, last Blender version (2.91.2)

Additional context
You might think that I could just force the JPG format at export, but if I had a normal map I'd not want to do that as it need to be PNG.
You might also think that I just have to bundle AO with R/M before exporting to JPG format. And while this would probably work this means that every time I bake a new AO texture I have to go outside of Blender and bundle it manually with R/M. To me that defeat the purpose of the exporter.

I think this issue was what started my issue:

When an image needs to be packed from channels, the packed image can sometimes be a JPEG if one of the constituents is (note: only sometimes!). This is lossy and causes channel-bleed (#818). I think a better default is to prefer being lossless.

If all constituents are JPEG I think the resulting packed image should be JPEG too. Yes this would cause some amount of bleed but
you decrease the size of the texture by a lot (up to 10 times?). If you choose to have AO/R/N as JPEG initially it means you care more about final glb size than quality. Or perhaps we should add an option regarding packed image format in the exporter?

@donmccurdy
Copy link
Contributor

Does #1099 address this, do you think? There was some discussion of export options and I'm not sure where it ended up.

@globglob3D
Copy link
Author

globglob3D commented Jan 28, 2021

Yes this totally address the issue, sorry I couldn't find the post before making mine. And I think you ended up with the right solution avoiding packing JPG with PNG all-together. But I've added a comment regarding multiple materials on that issue, I think you guys missed an important problem with automatic packing.

@julienduroure julienduroure added the duplicate This issue or pull request already exists label Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants