Repository: godotengine/godot (language: cpp)

Issue:
VoxelGI baking incorrectly when objects are rotated
### Tested versions

- Reproducible in: 4.1, 4.3, 4.4 beta1, 4.4 beta2 
- These are the only versions I tried

### System information

Windows 11 - RTX 4080 - Vulkan, MacOS - M4 - Vulkan

### Issue description

When baking a VoxelGI node, its results are completely off when an object within its bounds has any form of rotation. For example, consider a wall piece that is symetrical on both sides. The result of the voxel GI bake will be completely different if the wall has a 0 degree y-rotation or a 180 degree y-rotation. Objects that have a 90 degree or -90 degree rotation are even more problematic, since they cannot be rotated in any way to get a correct result:

Screenshots:
For all screenshots I set the Display mode in editor to VoxelGI Lighting.

Screenshot 1 - incorrect bake:  
![Image](https://github.com/user-attachments/assets/e56fe111-b410-4d14-a22f-a492fc9c32c7)
Notice the left wall is rotated 180 degrees along the y-axis.

Screenshot 2 - correct bake:
![Image](https://github.com/user-attachments/assets/3911ea82-d2d3-4987-82ec-771cc7384ae1)
Notice the left wall now has no rotation at all.

Screenshot 2 - incorrect bake:
![Image](https://github.com/user-attachments/assets/a4e48840-81ad-4308-a72c-aa1fd40a8245)
I now duplicated the back wall and rotated it 90 and -90 degrees for the left and right walls.



### Steps to reproduce

- Setup a scene with some modular pieces
- Add a light to the scene
- Add a VoxelGI node to the scene
- hit bake
- Now rotate 1 of you walls 180 degrees around the y-axis
- bake again and notice the different result

### Minimal reproduction project (MRP)

[VoxelGIBakingMRP.zip](https://github.com/user-attachments/files/18657147/VoxelGIBakingMRP.zip)


Discussion / hints:

Fix patch:
diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp
index 711b265bb641..a4c36deabdec 100644
--- a/scene/3d/voxelizer.cpp
+++ b/scene/3d/voxelizer.cpp
@@ -399,6 +399,9 @@ int Voxelizer::get_bake_steps(Ref<Mesh> &p_mesh) const {
 Voxelizer::BakeResult Voxelizer::plot_mesh(const Transform3D &p_xform, Ref<Mesh> &p_mesh, const Vector<Ref<Material>> &p_materials, const Ref<Material> &p_override_material, BakeStepFunc p_bake_step_func) {
 	ERR_FAIL_COND_V_MSG(!p_xform.is_finite(), BAKE_RESULT_INVALID_PARAMETER, "Invalid mesh bake transform.");
 
+	// Precalculate for transforming vertex normals
+	Basis normal_xform = p_xform.basis.inverse().transposed();
+
 	int bake_total = get_bake_steps(p_mesh), bake_current = 0;
 
 	for (int i = 0; i < p_mesh->get_surface_count(); i++) {
@@ -463,7 +466,7 @@ Voxelizer::BakeResult Voxelizer::plot_mesh(const Transform3D &p_xform, Ref<Mesh>
 
 				if (nr) {
 					for (int k = 0; k < 3; k++) {
-						normal[k] = nr[ir[j * 3 + k]];
+						normal[k] = normal_xform.xform(nr[ir[j * 3 + k]]).normalized();
 					}
 				}
 


Test patch: