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

oxipng transform turns transparent-black part of PNG to transparent-white #704

Closed
chgi opened this issue Oct 14, 2022 · 6 comments
Closed
Labels
bug Something isn't working dependencies Pull requests and issues related to dependencies
Milestone

Comments

@chgi
Copy link

chgi commented Oct 14, 2022

Describe the bug
I have a model with an attached PNG emissive texture.
For some reason, the texture has an alpha channel (I think it shouldn't be there, but we got it that way).
Using gltf-transform oxipng seems to turn all pixels that are transparent-black to transparent-white.

To Reproduce

  • Create a model in Blender
  • attach an emissive texture with alpha channel that has areas with RGBA=(0,0,0,0)
  • export to Demo.glb
  • execute NODE_OPTIONS="--no-experimental-fetch" gltf-transform oxipng Demo.glb Demo_oxipng.glb
  • view result in https://sandbox.babylonjs.com/
  • confirm that the areas that were previously RGBA=(0,0,0,0) turned to RGBA=(255,255,255,0)
  • since alpha should be ignored for emissive, the parts that were previously black are now white

Expected behavior
The RGB values should not change. Black should stay black.
I realize that that the RGB value of a fully transparent pixel should not matter, but this behaviour breaks the lossless promise of PNG.

Versions:

  • Version: cli.js 2.4.4
  • Environment: Windows 11, Node.js 18.10.0

Additional context
I tried to put the texture through oxipng standalone using https://squoosh.app/. The problem doesn't seem to occur there.

Before and after using gltf-transform oxipng
Before-After

Zip containing the source .blend file, the original texture and the glb before and after
Demo.zip

@chgi chgi added the bug Something isn't working label Oct 14, 2022
@donmccurdy
Copy link
Owner

Hi @chgi! Thanks for the bug report.

Unfortunately, I'm getting the same (incorrect) result when running the Squoosh CLI manually:

npm install --global @squoosh/cli
squoosh-cli --oxipng "{}" ~/Downloads/Demo/emit.png -d ~/Desktop/

glTF-Transform relies on the Node.js squoosh builds (@squoosh/lib) so it sounds like this may be an issue affecting only that version of the Squoosh codecs, and not their web app.

@donmccurdy donmccurdy added the dependencies Pull requests and issues related to dependencies label Oct 14, 2022
@chgi
Copy link
Author

chgi commented Oct 17, 2022

Hmm, I didn't think to test with the squoosh lib directly.

I investigated a bit and it looks like squoosh is deliberately enabling the alpha optimization of oxipng here.
This option seem seems to disabled by default exactly because stuff like I wrote above happens (see here).

Do you reckon, I should open a bug over at squoosh and ask them to at least expose the option to turn it off in the lib?

@donmccurdy
Copy link
Owner

I think it's worth filing the issue! They may not be aware that this makes a difference for WebGL, and perhaps other graphics-related use cases. Unfortunately it has been a while since the last squoosh updates were published.

@donmccurdy
Copy link
Owner

@chgi could you give this a try on your OS?

npm install --global @gltf-transform/cli@next

It's a prerelease for v3 (with #752), including sharp instead of squoosh. I believe sharp handles the alpha as expected here.

@donmccurdy donmccurdy added this to the v3.0 milestone Dec 21, 2022
@chgi
Copy link
Author

chgi commented Dec 21, 2022

@donmccurdy , thanks for the heads-up!

Just tried it with the attached file on Windows11, Node 18.12.
Using the originally attached files, the output seems correct now.

The output file size is a bit larger than with the old version (as expected), but still smaller than the input.

@donmccurdy
Copy link
Owner

Thanks! To be fixed in v3 with #752.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests and issues related to dependencies
Projects
None yet
Development

No branches or pull requests

2 participants