Repository: godotengine/godot (language: cpp)

Issue:
[4.4.dev7] Everything is black when baking shadows
### Tested versions

4.4.dev6 - Everything is working fine
4.4.dev7 - It works with an error

Render - Compatibility

### System information

Godot Engine v4.4.dev7.official.46c8f8c5c - https://godotengine.org OpenGL API 4.6 (Core Profile) Mesa 23.3.6 - Compatibility - Using Device: AMD - AMD Radeon Graphics

### Issue description

When baking lightmaps after export on Android, everything turns black.

Errors that the debugger issues

```
  ERROR: Cannot convert to (or from) compressed formats. Use compress() and decompress() instead.
  ERROR: drivers/gles3/storage/texture_storage.cpp:1763 - Parameter "texture" is null.
  ERROR: Cannot convert to (or from) compressed formats. Use compress() and decompress() instead.
```

### Steps to reproduce

Video of the baking process
![Video](https://github.com/user-attachments/assets/0fa6575b-5b2b-4976-b799-afad7edcd307)

Everything that falls under the action of baking turns black.

This is how it looks on my phone.

![Image](https://github.com/user-attachments/assets/ac697266-53e2-4547-854c-c36653f5cbf0)


### Minimal reproduction project (MRP)

This happens in all my projects, even in an empty project.


Discussion / hints:
Phone - realme 9 4G 6/128
> This happens in all my projects, even in an empty project.

Could you provide such a minimal project set up for baking lightmaps with shadows that triggers the error?

You mention you're baking lightmaps on Android, but the GPU information in the video points at AMD graphics, which I doubt is what you have on a Realme 9 (which seems to be using Qualcomm's Snapdragon). So I'm a bit confused.

Is the video from a Linux PC with Mesa and AMD, and then the results of the failed bake are then shown from the Android phone? Or are you actually using the Android editor and it's just misreporting its GPU details?
The games are exported to Android from Linux.

There are no problems on the PC.

I will prepare the minimum project only in the evening when I return from work.

At the moment, the problem concerns any of my projects.

They have different settings, I'll put together the one that was used in the video project.

I don't use the Android editor. Android is the target platform for the game itself. Google Play.
I edited the message so that there would be no confusion.
Could you try setting the baked lightmap texture's import settings to VRAM Uncompressed? This may be related to ASTC HDR not working as intended
I'll try to do it tonight.
![Image](https://github.com/user-attachments/assets/50cbf9b0-9b69-45ce-9715-bdf6eb494e3f)
An error also occurs when opening the editor (if it was previously closed). This is probably really related to the import, and not to the baking itself.
The number of errors is equal to the number of exr files.
Here are the import settings where the colors are normal. There are no mistakes.

![Image](https://github.com/user-attachments/assets/742171b8-f76a-48c2-ab5b-2ce081631719)

![Image](https://github.com/user-attachments/assets/e9cd1c91-80d1-4003-83e5-67ad836a873a)

But with these parameters, everything turns black and the console reports an error.


![Image](https://github.com/user-attachments/assets/10da754c-3523-44fc-bf0b-03374fa91d8b)

This may be caused by #96045, or simply by your phone not supporting ASTC compression (though not likely). CC @darksylinc 
> This may be caused by [#96045](https://github.com/godotengine/godot/pull/96045), or simply by your phone not supporting ASTC compression (though not likely). CC [@darksylinc](https://github.com/darksylinc)

That PR affects Vulkan only and OP is reporting the error happening on Compatibility/GLES.
> ![Image](https://github.com/user-attachments/assets/50cbf9b0-9b69-45ce-9715-bdf6eb494e3f) An error also occurs when opening the editor (if it was previously closed). This is probably really related to the import, and not to the baking itself. The number of errors is equal to the number of exr files.

This is an unrelated issue that should be fixed by https://github.com/godotengine/godot/pull/100778
Could you try exporting this project to your phone and posting the results? [compat-hdr-comp-test.zip](https://github.com/user-attachments/files/18247348/compat-hdr-comp-test.zip)

For reference, this is how it should look like:
![Image](https://github.com/user-attachments/assets/b634bb2c-6d87-4dae-a8a4-6dd46b5752ee)



Fix patch:
diff --git a/modules/astcenc/SCsub b/modules/astcenc/SCsub
index 23e9fa87fc12..bb8bc8d86778 100644
--- a/modules/astcenc/SCsub
+++ b/modules/astcenc/SCsub
@@ -41,6 +41,13 @@ env_astcenc.Prepend(CPPPATH=[thirdparty_dir])
 
 env_thirdparty = env_astcenc.Clone()
 env_thirdparty.disable_warnings()
+
+# Build the encoder only for editor builds
+astc_encoder = env.editor_build
+
+if not astc_encoder:
+    env_thirdparty.Append(CPPDEFINES=[("ASTCENC_DECOMPRESS_ONLY")])
+
 env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
 env.modules_sources += thirdparty_obj
 
diff --git a/modules/astcenc/config.py b/modules/astcenc/config.py
index 37bb65f8ae77..d22f9454ed25 100644
--- a/modules/astcenc/config.py
+++ b/modules/astcenc/config.py
@@ -1,7 +1,5 @@
 def can_build(env, platform):
-    # Godot only uses it in the editor, but ANGLE depends on it and we had
-    # to remove the copy from prebuilt ANGLE libs to solve symbol clashes.
-    return env.editor_build or env.get("angle_libs")
+    return True
 
 
 def configure(env):
diff --git a/modules/astcenc/image_compress_astcenc.cpp b/modules/astcenc/image_compress_astcenc.cpp
index 31cfe4b90255..c074f3ebb4f2 100644
--- a/modules/astcenc/image_compress_astcenc.cpp
+++ b/modules/astcenc/image_compress_astcenc.cpp
@@ -35,6 +35,7 @@
 
 #include <astcenc.h>
 
+#ifdef TOOLS_ENABLED
 void _compress_astc(Image *r_img, Image::ASTCFormat p_format) {
 	const uint64_t start_time = OS::get_singleton()->get_ticks_msec();
 
@@ -171,6 +172,7 @@ void _compress_astc(Image *r_img, Image::ASTCFormat p_format) {
 
 	print_verbose(vformat("astcenc: Encoding took %d ms.", OS::get_singleton()->get_ticks_msec() - start_time));
 }
+#endif // TOOLS_ENABLED
 
 void _decompress_astc(Image *r_img) {
 	const uint64_t start_time = OS::get_singleton()->get_ticks_msec();
@@ -213,8 +215,9 @@ void _decompress_astc(Image *r_img) {
 
 	astcenc_config config;
 	const float quality = ASTCENC_PRE_MEDIUM;
+	const uint32_t flags = ASTCENC_FLG_DECOMPRESS_ONLY;
 
-	astcenc_error status = astcenc_config_init(profile, block_x, block_y, 1, quality, 0, &config);
+	astcenc_error status = astcenc_config_init(profile, block_x, block_y, 1, quality, flags, &config);
 	ERR_FAIL_COND_MSG(status != ASTCENC_SUCCESS,
 			vformat("astcenc: Configuration initialization failed: %s.", astcenc_get_error_string(status)));
 
diff --git a/modules/astcenc/image_compress_astcenc.h b/modules/astcenc/image_compress_astcenc.h
index ad157d7c0a66..790a3bd3229d 100644
--- a/modules/astcenc/image_compress_astcenc.h
+++ b/modules/astcenc/image_compress_astcenc.h
@@ -33,7 +33,10 @@
 
 #include "core/io/image.h"
 
+#ifdef TOOLS_ENABLED
 void _compress_astc(Image *r_img, Image::ASTCFormat p_format);
+#endif
+
 void _decompress_astc(Image *r_img);
 
 #endif // IMAGE_COMPRESS_ASTCENC_H
diff --git a/modules/astcenc/register_types.cpp b/modules/astcenc/register_types.cpp
index 0bb1c3432f8e..ca0f317fa946 100644
--- a/modules/astcenc/register_types.cpp
+++ b/modules/astcenc/register_types.cpp
@@ -37,7 +37,10 @@ void initialize_astcenc_module(ModuleInitializationLevel p_level) {
 		return;
 	}
 
+#ifdef TOOLS_ENABLED
 	Image::_image_compress_astc_func = _compress_astc;
+#endif
+
 	Image::_image_decompress_astc = _decompress_astc;
 }
 


Test patch: