godotengine / godot

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

Changes to Primitive Meshes Texel Size project setting do not apply until the scene is reloaded #94637

Closed Calinou closed 3 weeks ago

Calinou commented 1 month ago

Tested versions

System information

Godot v4.3.beta (92c8e87cd) - Fedora Linux 40 (KDE Plasma) - X11 - GLES3 (Compatibility) - NVIDIA GeForce RTX 4090 (nvidia; 555.58.02) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

Issue description

Changes to lightmapping's Primitive Meshes Texel Size project setting do not apply until the scene is reloaded. This requires you to restart the editor or use Scene > Reload Saved Scene after saving the current scene to be able to use the updated texel size for LightmapGI baking.

We should listen to the project_settings changed signal somewhere and regenerate all PrimitiveMeshes when that particular project setting's value changes.

cc @BastiaanOlij

Steps to reproduce

Minimal reproduction project (MRP)

N/A

clayjohn commented 1 month ago

I would just change it to a GLOBAL_DEF_RST property instead. The situation is a bit awkward since the texel size, once changed, will apply to all new or changed meshes.

Ultimately, since this really only impacts editor stuff, I think it is best to take the simplest solution so we don't have to add a bunch of complexity to the PrimitiveMeshes for a feature that won't even be useful at run time.

Calinou commented 1 month ago

I would just change it to a GLOBAL_DEF_RST property instead.

It doesn't actually require an editor restart, just a reload of the current scene. That's why I feel GLOBAL_DEF_RST() would be overkill here, as it would lead to users thinking they have to restart the editor to see changes (which is quite a bit slower than just reloading the scene).

There could be a dedicated hint for project settings that require a scene reload to apply, but that would also be a fair amount of changes to implement.

BastiaanOlij commented 1 month ago

Looks pretty straight forward, I think if we retrieve the texel size in the constructor on PrimitiveMesh and connect to the ProjectSettings.settings_changed signal, we can easily react to it:

So basically:

void PrimitiveMesh::_on_settings_changed() {
    float new_texel_size = GLOBAL_GET("rendering/lightmapping/primitive_meshes/texel_size");
    if (texel_size != new_texel_size) {
        texel_size = new_texel_size;
        _update_lightmap_size();
        request_update();
    }
}

I'll write up a PR later tonight.