-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Option for Texture Importer to ignore image alpha #81803
base: master
Are you sure you want to change the base?
Conversation
One of the checks failed but it doesn't look even closely related to the code submitted. Is everything OK with the checker? |
I believe this should be discarded automatically based on the presence of a transparent pixel (alpha < 1.0) in the source image, instead of asking the user to tick a checkbox. We have a method in the Image class for this 🙂 |
I believe it should be both. In the best case, there should be an "Override format" drop-down that allows the user to select something alike RGBA4444 when needed without guessing the desired format. In my case, non-transparent texture atlases could have transparent pixels due to atlasing software adding borders and aligning elements to a grid. However, I still treat those textures as fully opaque and don't need an Alpha channel there. |
There was a proposal requesting the ability to force an arbitrary pixel format, but there's not much demand for it: godotengine/godot-proposals#2107 |
Don’t see why it wasn’t implemented. It’s a useful feature for many cases. At the moment I lack the knowledge of internal options mechanisms to implement it, but I’ll look if it can be done in a few hours. |
Does force format have a default option? I am placing this workflow as if there are a 1000 assets in a Godot Engine repository. Making manual changes would take a lot of time. |
While the core team is still deciding if we need an explicit format selection, I've added more modes to the Channel Pack drop-down. You need to choose if we are taking this route (extending the Channel Pack) or this one. Screen.Recording.2023-09-21.at.10.33.21.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment style changes
I'm a little unsure about this. AFAIK our current importer already checks whether the alpha channel is used, if it isn't, then it automatically drops the alpha channel. Are you saying that you have textures where the alpha value is less than 255, but nevertheless alpha should be ignored? For context, our importer looks at the texture, if all alpha bits are 255, it can ignore alpha and use another, more compressed format, if all alpha bits are 0 or 1, it assumes a binary alpha value and uses a compatible format, otherwise it keeps the four channel format. |
Once again checks fail in some unrelated parts. |
Unrelated to your PR, this is being investigated: |
There is an Image method that checks for actual non-opaque pixels, and could be used to detect whether DXT5 is worth using over DXT1. I think the approach in your PR has merits (especially if support for high bit depth PNG is implemented in the future, as it would remain RGB(A)8 by default for performance reasons). That said, we need to make sure the "default" path provides a good level of optimization, as most users will not tweak it manually. |
It's already used in godot/drivers/png/png_driver_common.cpp. I confirm that it doesn't work with the first of the images posted above and will not work for the other cases I mentioned:
|
In some workflows opaque images are stored in with alpha channel that results in DXT5 and other compression formats with abundant data. This patch adds an option to Channel Pack dropdown to ignore alpha channel. It works only for non-HDR RGBAF, RGBAH and RGBA8 images.
bfb1220
to
567ac14
Compare
use_uncompressed = true; | ||
} | ||
} | ||
} else if (pack_channels == 2) { // Discard alpha. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous if statement here (is_hdr) is checking has_alpha, but we should be setting has_alpha to false if pack_channels == 2 or 4 or some of the other numbers.
@@ -586,6 +586,18 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String | |||
} | |||
} | |||
} | |||
|
|||
if (pack_channels == 3) { // BGRA mode, swapping B and R channels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way too specific. A user is going to read BGRA and assume it means RGBA since there is no RGBA option currently.
I think it might be interesting to support remapping color channels (and specifying invert / 1-x for each) but we should make this its own proposal. Honestly that would also give an ideal place to drop unwanted / unused color channels (set them to 0 or 1 for alpha). Then, the Optimized case can handle discarding those all-0 and all-1 channels the same way it does now. Here's my proposal. Ideally it can be collapsed, but maybe it's ok if it's at the bottom of the Texture import dock Per-channel settings ▸
And then if you want R-only you set green, blue and alpha to Unused. |
In some workflows, opaque images are stored in with alpha channel that results in DXT5 and other compression formats with abundant data. This patch adds an option to the Channel Pack dropdown to ignore the alpha channel. It works only for non-HDR RGBAF, RGBAH, and RGBA8 images.
Correctly cherry-picked and fixed.