-
-
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
Open
Nomad1
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
Nomad1:image_opaque_ench
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,7 @@ void ResourceImporterTexture::get_import_options(const String &p_path, List<Impo | |
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_compression", PROPERTY_HINT_ENUM, "Disabled,Opaque Only,Always"), 1)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/normal_map", PROPERTY_HINT_ENUM, "Detect,Enable,Disabled"), 0)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/channel_pack", PROPERTY_HINT_ENUM, "sRGB Friendly,Optimized"), 0)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/channel_pack", PROPERTY_HINT_ENUM, "sRGB Friendly,Optimized,Opaque RGB,BGRA,Only R Channel,Only RG channels"), 0)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "mipmaps/generate"), (p_preset == PRESET_3D ? true : false))); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "mipmaps/limit", PROPERTY_HINT_RANGE, "-1,256"), -1)); | ||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "roughness/mode", PROPERTY_HINT_ENUM, "Detect,Disabled,Red,Green,Blue,Alpha,Gray"), 0)); | ||
|
@@ -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. | ||
const int height = target_image->get_height(); | ||
const int width = target_image->get_width(); | ||
|
||
for (int i = 0; i < width; i++) { | ||
for (int j = 0; j < height; j++) { | ||
const Color color = target_image->get_pixel(i, j); | ||
target_image->set_pixel(i, j, Color(color.b, color.g, color.r, color.a)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) { | ||
|
@@ -643,6 +655,18 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String | |
use_uncompressed = true; | ||
} | ||
} | ||
} else if (pack_channels == 2) { // Discard alpha. | ||
Comment on lines
655
to
+658
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (image->get_format() == Image::FORMAT_RGBAF) { | ||
image->convert(Image::FORMAT_RGBF); | ||
} else if (image->get_format() == Image::FORMAT_RGBAH) { | ||
image->convert(Image::FORMAT_RGBH); | ||
} else if (image->get_format() == Image::FORMAT_RGBA8) { | ||
image->convert(Image::FORMAT_RGB8); | ||
} | ||
} else if (pack_channels == 4) { // Discard all channels except R. | ||
image->convert(Image::FORMAT_R8); | ||
} else if (pack_channels == 5) { // Discard all channels except RG. | ||
image->convert(Image::FORMAT_RG8); | ||
} | ||
|
||
if (use_uncompressed) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.