godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.22k stars 21.22k forks source link

Lossless WebP import does not make use of grayscale (L8/LA8) formats when possible #56523

Open Calinou opened 2 years ago

Calinou commented 2 years ago

Godot version

4.0.dev (1032c2c43), 3.x (08ce24a3c), 3.4.2.stable

System information

Fedora 34, GeForce GTX 1080 (NVIDIA 495.46)

Issue description

Unlike PNG compression, lossless WebP compression (enabled by default since Godot 3.4) will not use the L8/LA8 formats (referred to as Lum8 and LumAlpha8 in the inspector preview). Instead, RGB8 or RGBA8 will always be used, which wastes memory.

This can be worked around by enabling Force Png in the Project Settings then reimporting all textures that are imported with lossless compression.

See my complete investigation here: https://github.com/godotengine/godot-proposals/issues/2107#issuecomment-1005752219

cc @mortarroad

Steps to reproduce

Minimal reproduction project

master: test_image_formats.zip

3.x: test_image_formats_3.x.zip

mortarroad commented 2 years ago

WebP only supports a limited set of formats. The only ones that are of interest to us are RGB and RGBA. (The others are YUV and other exotic things.)

I see 2 options:

If we want to go the route with storing a hint, we should also look into checking which channels are used during import, to make sure a grayscale texture always gets loaded as grayscale, even if the PNG file is RGB.

Calinou commented 2 years ago

If we want to go the route with storing a hint, we should also look into checking which channels are used during import, to make sure a grayscale texture always gets loaded as grayscale, even if the PNG file is RGB.

I think this would be the ideal solution, as not everyone saves their grayscale images with a grayscale format. It would slow down importing a little as every pixel's color needs to be checked, but I think it's worth it.