godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Allow to invert texture colors in the default importer #9618

Open Souchy opened 2 weeks ago

Souchy commented 2 weeks ago

Describe the project you are working on

Tool applications for desktop.

Describe the problem or limitation you are having in your project

Standard icons usually come in black, which can't be modulated directly. I.E. on button icons.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The feature would invert the rgb channels, i.e. making black icons white. Having this in an importer speeds up the process of inverting every texture. It could also be interesting to have a grayscale modifier in combination with this.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

ResourceImporterTexture::import

    r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/invert_color"), false));
    const bool invert_color = p_options["process/invert_color"];
        // Invert rgb channels
        if(invert_color) {
            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);
                    const Color inverted = Color(1 - color.r, 1 - color.g, 1 - color.b, color.a);
                    target_image->set_pixel(i, j, inverted);
                }
            }
        }

If this enhancement will not be used often, can it be worked around with a few lines of script?

It could be an importer script.

Is there a reason why this should be core and not an add-on in the asset library?

I believe it could useful to a lot of people, and less of a hassle, therefore better to be built in the engine.

Calinou commented 2 weeks ago

Note that this was available in 3.x, but was removed in 4.0 as we didn't see any use cases for it back then: https://github.com/godotengine/godot/pull/39202

VideoGirlAi commented 2 weeks ago

I decided to finally start converting my Godot 3 project to Godot 4, and was in the process of importing my bitmap fonts. I make my bitmap fonts textures in black, as it's easy to see in my image editor, and then I would invert colors on import so that the font is white in Godot. I'm pretty sad to see that this option is gone. I hope it can be re-implemented.